我正在做一个从 url 读取 xml 并将其显示在屏幕上的应用程序,但是当我想阅读答案时,我会收到 FileNotFoundException
这是代码:
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
ListView rss = (ListView) findViewById(R.id.list);
try {
Authenticator.setDefault(new Authenticator() {
@Override
protected PasswordAuthentication getPasswordAuthentication() {
return new PasswordAuthentication("acceso!a!backend", "nu3v0!1nf0b43!2013".toCharArray());
}
});
URL rssUrl = new URL("http://ec2-54-224-94-185.compute-1.amazonaws.com/adjuntos/162/rss/home_mobile.xmlx");
SAXParserFactory factory = SAXParserFactory.newInstance();
SAXParser saxParser = factory.newSAXParser();
XMLReader xmlReader = saxParser.getXMLReader();
RSSHandler rssHandler = new RSSHandler();
xmlReader.setContentHandler(rssHandler);
////////这里我得到了 FileNotFoundException
InputSource inputSource = new InputSource(rssUrl.openStream());
xmlReader.parse(inputSource);
NoticiasAdapter na = new NoticiasAdapter(this ,rssHandler.getChannel());
rss.setAdapter(na);
} catch (IOException e) {
e.printStackTrace();
} catch (SAXException e) {
e.printStackTrace();
} catch (ParserConfigurationException e) {
e.printStackTrace();
}
}