我是 Android 新手,我做了一个简单的应用程序,它从 XML RSS 提要中读取数据,并将其呈现给用户。它在 android 2.2 或更高版本的电话和 android 2.1 的模拟器上运行良好,但在 android 2.1 的电话上规范化 DOM 文档时抛出异常。
这是代码的一部分:
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
DocumentBuilder db = dbf.newDocumentBuilder();
Document dom = db.parse(in);
Element docEle = dom.getDocumentElement();
dom.normalize();
NodeList nl = docEle.getElementsByTagName("item");
if (nl != null && nl.getLength() > 0) {
//some stuff here
}
根据指令 dom.normalize() 应用程序抛出以下异常:
06-15 17:20:01.161: ERROR/ActivityManager(79): fail to set top app changed!
06-15 17:20:07.501: ERROR/AndroidRuntime(1199): Uncaught handler: thread refresh_news exiting due to uncaught exception
06-15 17:20:07.531: ERROR/AndroidRuntime(1199): org.w3c.dom.DOMException
06-15 17:20:07.531: ERROR/AndroidRuntime(1199): at org.apache.harmony.xml.dom.InnerNodeImpl.removeChild(InnerNodeImpl.java:184)
06-15 17:20:07.531: ERROR/AndroidRuntime(1199): at org.apache.harmony.xml.dom.InnerNodeImpl.normalize(InnerNodeImpl.java:161)
06-15 17:20:07.531: ERROR/AndroidRuntime(1199): at com.krawczyk.lech.services.NewsService.doRefreshNews(NewsService.java:231)
06-15 17:20:07.531: ERROR/AndroidRuntime(1199): at com.krawczyk.lech.services.NewsService.access$0(NewsService.java:209)
06-15 17:20:07.531: ERROR/AndroidRuntime(1199): at com.krawczyk.lech.services.NewsService$1.run(NewsService.java:201)
06-15 17:20:07.531: ERROR/AndroidRuntime(1199): at java.lang.Thread.run(Thread.java:1102)
06-15 17:20:07.551: ERROR/dalvikvm(1199): Unable to open stack trace file '/data/anr/traces.txt': Permission denied
这是Android 2.1的普遍问题还是我的错误?请帮忙。