简体   繁体   English

java.lang.RuntimeException:java.net.UnknownHostException:主机未解析:

[英]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? 我在解析XML文件时遇到问题,我使用了newsRSS解析器作为参考。但是我在真实设备中遇到此错误。如何为用户显示错误消息(如警报),让他留在应用程序中而不会崩溃?

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 :) 感谢帮助 :)

如果这在emulator而不是在device ,则很可能是因为您的device上没有InternetConnection ,或者您尝试访问的Feed URL也无法从device所连接的Network访问。

i already has this problem , the host is unresolved means that the url is unreachable , or your connection is tooo Sloow . 我已经有这个问题,无法host is unresolvedhost is unresolved意味着URL无法访问,或者您的连接太Sloow了。 try to test your programm with another Internet Connexion which has a good Bandwidth : 尝试使用另一个具有良好带宽的Internet连接来测试您的程序:

Also , check that your Emulator display the icon of 3G . 另外,检查模拟器是否显示3G图标。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM