Problem with parsing DOM on 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.开发者_C百科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.
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.
精彩评论