Ahmad Hariss
Ahmad Hariss

Reputation: 27

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 message 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 :)

Upvotes: 0

Views: 3243

Answers (2)

Houcine
Houcine

Reputation: 24181

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 .

Upvotes: 0

Ovidiu Latcu
Ovidiu Latcu

Reputation: 72331

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.

Upvotes: 1

Related Questions