0

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

1
  • Your log message is not very helpful. It does not give any indication of what the error actually was. Commented Sep 29, 2011 at 14:33

2 Answers 2

1

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.

Sign up to request clarification or add additional context in comments.

Comments

0

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 .

2 Comments

Yes you are right,sometimes the host unreachable. but my point is: how i can detect if my request is done or not? and alert the user of the app about this?
you have catched the exception that your code may throw , so you can alert the user on the bloc Catch() by displaying a Toast or alertDialog, the same thing when your code request is done very well , display a Toast:)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.