我正在 Android 上构建一个新闻阅读器;尽管我把线放在了正确的位置
<uses-permission
android:name="android.permission.INTERNET" />
当我从方法 getInputStream() 获取输入流时,我总是得到未知主机异常......它有什么问题?这让我疯狂...
public List<NewsPreview> parse(){
SAXParserFactory factory = SAXParserFactory.newInstance();
try {
SAXParser parser = factory.newSAXParser();
FeedHandler handler = new FeedHandler();
parser.parse(this.getInputStream(), handler);
return handler.getNewsList();
} catch (Exception e) {
throw new RuntimeException(e);
}
}
private InputStream getInputStream() {
try {
return feedUrl.openConnection().getInputStream();
} catch (IOException e) {
throw new RuntimeException(e);
}
}