gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-01 15:43:29 25 4
gpt4 key购买 nike

我在解析 XML 文件时遇到问题,我使用 newsRSS 解析器作为引用。但我在真实设备中收到此错误。如何向用户显示警告等错误消息并让他留在应用程序上没有崩溃?

这是进行连接和解析的代码:

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);
}
}

如何在不崩溃或退出应用程序的情况下向用户发送警报来处理此错误?

感谢您的帮助:)

最佳答案

如果这在模拟器中有效,但在您的设备上无效,则很可能是因为您的上没有InternetConnection设备 或您尝试访问的Feed URL 也无法从您的设备 连接的网络 访问。

关于java.lang.RuntimeException : java.net.UnknownHostException:主机未解析:,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7598817/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com