Android 2.1上解析DOM的问题
我是 Android 新手,我制作了一个简单的应用程序,它从 XML RSS feed 读取数据,并将其呈现给用户。它在 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 的普遍问题还是我的错误?请帮忙。
I am Android newbie and I made simple application which reads data from XML RSS feed, and presents it to the user. It works fine on telephone with android 2.2 or greater and on emulator with android 2.1, but throws exception on normalizing DOM document on telephones with android 2.1.
Here is the part of code:
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
}
at line with instruction dom.normalize() application throws following exception:
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
Is it a general problem of Android 2.1 or is it my mistake?? Please help.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我进行了搜索并找到了这个 博客,它描述了bug出现在sdk 7中,该bug导致qName为空并且localname被您的XML元素值填充。那里还发布了一个解决方案。
我相信你可能会面临同样的问题。
I did a search and find this blog, it describes a bug appears in sdk 7, of which the bug causes the qName to be empty and the localname to be filled with your XML element value. there is also a solution posted there.
I believe you may face the same problem.