Android 内存不足错误

发布于 2024-10-05 06:22:56 字数 2462 浏览 8 评论 0原文

当尝试使用 SAXParser 解析大型 XML 文件时,我的应用程序崩溃了。
我在 SO 中发现了一个关于它的问题这里未得到解答。
当我减小 XML 的大小时,它按预期工作
这是我的 LogCat 输出。

11-26 12:08:45.099: WARN/dalvikvm(218): threadid=17: thread exiting with uncaught exception (group=0x4001aa28)
11-26 12:08:45.109: ERROR/AndroidRuntime(218): Uncaught handler: thread Thread-9 exiting due to uncaught exception
11-26 12:08:45.220: ERROR/AndroidRuntime(218): java.lang.OutOfMemoryError
11-26 12:08:45.220: ERROR/AndroidRuntime(218):     at java.lang.Object.internalClone(Native Method)
11-26 12:08:45.220: ERROR/AndroidRuntime(218):     at java.lang.Object.clone(Object.java:82)
11-26 12:08:45.220: ERROR/AndroidRuntime(218):     at java.lang.AbstractStringBuilder.append0(AbstractStringBuilder.java:141)
11-26 12:08:45.220: ERROR/AndroidRuntime(218):     at java.lang.StringBuilder.append(StringBuilder.java:282)
11-26 12:08:45.220: ERROR/AndroidRuntime(218):     at   com.google.android.iopex.SaxXMLHandler.characters(SaxXMLHandler.java:24)
11-26 12:08:45.220: ERROR/AndroidRuntime(218):     at org.apache.harmony.xml.ExpatParser.text(ExpatParser.java:166)
11-26 12:08:45.220: ERROR/AndroidRuntime(218):     at org.apache.harmony.xml.ExpatParser.append(Native Method)
11-26 12:08:45.220: ERROR/AndroidRuntime(218):     at org.apache.harmony.xml.ExpatParser.parseFragment(ExpatParser.java:506)
11-26 12:08:45.220: ERROR/AndroidRuntime(218):     at org.apache.harmony.xml.ExpatParser.parseDocument(ExpatParser.java:467)
11-26 12:08:45.220: ERROR/AndroidRuntime(218):     at org.apache.harmony.xml.ExpatReader.parse(ExpatReader.java:329)
11-26 12:08:45.220: ERROR/AndroidRuntime(218):     at org.apache.harmony.xml.ExpatReader.parse(ExpatReader.java:286)
11-26 12:08:45.220: ERROR/AndroidRuntime(218):     at javax.xml.parsers.SAXParser.parse(SAXParser.java:361)
11-26 12:08:45.220: ERROR/AndroidRuntime(218):     at javax.xml.parsers.SAXParser.parse(SAXParser.java:240)
11-26 12:08:45.220: ERROR/AndroidRuntime(218):     at com.google.android.iopex.SaxParser.parse(SaxParser.java:22)
11-26 12:08:45.220: ERROR/AndroidRuntime(218):     at com.google.android.iopex.iOPEXActivity$4.run(iOPEXActivity.java:112)
11-26 12:08:45.220: ERROR/AndroidRuntime(218):     at java.lang.Thread.run(Thread.java:1060)

这里是我用来解析的代码

My application is crashing when trying to parse a large XML file using SAXParser.
I found a question in SO regarding it here unanswered.
It is working as intended when i reduce the size of the XML
Here is my LogCat output.

11-26 12:08:45.099: WARN/dalvikvm(218): threadid=17: thread exiting with uncaught exception (group=0x4001aa28)
11-26 12:08:45.109: ERROR/AndroidRuntime(218): Uncaught handler: thread Thread-9 exiting due to uncaught exception
11-26 12:08:45.220: ERROR/AndroidRuntime(218): java.lang.OutOfMemoryError
11-26 12:08:45.220: ERROR/AndroidRuntime(218):     at java.lang.Object.internalClone(Native Method)
11-26 12:08:45.220: ERROR/AndroidRuntime(218):     at java.lang.Object.clone(Object.java:82)
11-26 12:08:45.220: ERROR/AndroidRuntime(218):     at java.lang.AbstractStringBuilder.append0(AbstractStringBuilder.java:141)
11-26 12:08:45.220: ERROR/AndroidRuntime(218):     at java.lang.StringBuilder.append(StringBuilder.java:282)
11-26 12:08:45.220: ERROR/AndroidRuntime(218):     at   com.google.android.iopex.SaxXMLHandler.characters(SaxXMLHandler.java:24)
11-26 12:08:45.220: ERROR/AndroidRuntime(218):     at org.apache.harmony.xml.ExpatParser.text(ExpatParser.java:166)
11-26 12:08:45.220: ERROR/AndroidRuntime(218):     at org.apache.harmony.xml.ExpatParser.append(Native Method)
11-26 12:08:45.220: ERROR/AndroidRuntime(218):     at org.apache.harmony.xml.ExpatParser.parseFragment(ExpatParser.java:506)
11-26 12:08:45.220: ERROR/AndroidRuntime(218):     at org.apache.harmony.xml.ExpatParser.parseDocument(ExpatParser.java:467)
11-26 12:08:45.220: ERROR/AndroidRuntime(218):     at org.apache.harmony.xml.ExpatReader.parse(ExpatReader.java:329)
11-26 12:08:45.220: ERROR/AndroidRuntime(218):     at org.apache.harmony.xml.ExpatReader.parse(ExpatReader.java:286)
11-26 12:08:45.220: ERROR/AndroidRuntime(218):     at javax.xml.parsers.SAXParser.parse(SAXParser.java:361)
11-26 12:08:45.220: ERROR/AndroidRuntime(218):     at javax.xml.parsers.SAXParser.parse(SAXParser.java:240)
11-26 12:08:45.220: ERROR/AndroidRuntime(218):     at com.google.android.iopex.SaxParser.parse(SaxParser.java:22)
11-26 12:08:45.220: ERROR/AndroidRuntime(218):     at com.google.android.iopex.iOPEXActivity$4.run(iOPEXActivity.java:112)
11-26 12:08:45.220: ERROR/AndroidRuntime(218):     at java.lang.Thread.run(Thread.java:1060)

HERE is the code that i'm using to parse

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

爱你是孤单的心事 2024-10-12 06:23:05

Android 有堆限制,从文件中读取块中的 XML 数据并方便地解析它

Ninja 编辑:

根据 Tseng :通过读取 20-30 个条目来缓存 List 更有意义。

There are heap restrictions for android, read the XML data in chunks from your file and parse it conveniently

Ninja edit:

As per Tseng : Caching List<DbEntry> by reading 20-30 entries into it makes much more sense.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文