未经许可,未知主机异常

时间:2011-11-09 13:13:26

标签: android inputstream unknown-host

我在Android上建立了一个新闻阅读器;尽管我把这条线放在了正确的位置

 <uses-permission
    android:name="android.permission.INTERNET" />

当我从方法getInputStream()获取输入流时,我总是得到Unknown主机异常...它有什么问题?这让我发疯了......

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

0 个答案:

没有答案