ArrayIndexOutOfBoundsException in android's KXmlParser

孤街醉人 提交于 2019-12-01 16:36:21

I have a similar exception. In my case, the xml had been downloaded and saved to the SD. When I opened the file, I saw that it cut out "mid-sentence", as it were. It looked like there had been an error in downloading the file. Deleting the file and re-downloading fixed the issue in this instance, but to prevent future issues of the same type, I check for ArrayIndexOutOfBoundsException when reading an xml, and assume the file is corrupt when it catches one.

It's obviously just a bandaid solution to a vaguely defined problem at the moment. If I figure more out, I'll update my answer.

I found a bug-fix for Android 4.4 mentioning this: Change 61530

So the proper exception you should be getting is: Unterminated element content spec, meaning unexpected EOF.

The lower layer (kxml) is incorrectly throwing an unchecked Exception when it encounters bad xml. To workaround this, when using XmlPullParser, replace

try {
    // use XmlPullParser
}
catch (XmlPullParserException ex) { ... }

with

try {
    // use XmlPullParser
}
catch (Exception ex) { ... }
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!