开发者

java.lang.RuntimeException: java.net.UnknownHostException: Host is unresolved:

I am having a problem while parsing XML file,i used newsRSS parser as a reference.but i am getting this error in the real device.how to display an error m开发者_开发知识库essage like alert for the user and let him stay on the app without crashing?

this is the peace of the code that do the connection and parsing:

protected Config_Parser(String feedUrlString,Context context){
  this.context = context;
  try {
    this.feedUrl = new URL(feedUrlString);
  } catch (MalformedURLException e) {
    throw new RuntimeException(e);
  }
}
protected InputStream getInputStream() {
  try {
    return feedUrl.openConnection().getInputStream();
  } catch (IOException e) {
    Log.e("Error", "error happned");
    return null;
    //throw new RuntimeException(e);
  }
}

how may i handle this error with sending alert to the user without crashing or exiting the application?

Thanks for help :)


If this works in the emulator and not on your device it is most likely because you do not have InternetConnection on your device or the Feed URL that you are trying to access is not accessible from the Network that your device is connected too.


i already has this problem , the host is unresolved means that the url is unreachable , or your connection is tooo Sloow . try to test your programm with another Internet Connexion which has a good Bandwidth :

Also , check that your Emulator display the icon of 3G .

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜