了java.lang.RuntimeException:的java.net.UnknownHostException:主机是没有得到解决: [英] java.lang.RuntimeException: java.net.UnknownHostException: Host is unresolved:

查看:1802
本文介绍了了java.lang.RuntimeException:的java.net.UnknownHostException:主机是没有得到解决:的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个问题,在解析XML文件,我用newsRSS分析器作为reference.but我得到了真正的device.how这个错误,显示一个类似的警报,为用户的错误信息,让他留在应用程序没有崩溃?

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?

这是code,它做的连接和解析和平:

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?

感谢您的帮助:)

推荐答案

如果这部作品在仿真器,而不是你的设备因为你没有拥有它是最有可能的 InternetConnection 设备饲料网址您试图访问不是从网​​络你的设备访问连接​​了。

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.

这篇关于了java.lang.RuntimeException:的java.net.UnknownHostException:主机是没有得到解决:的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆