Android OutOfMemoryError

时间:2010-11-26 07:10:55

标签: java android heap saxparser xml-parsing

尝试使用SAXParser解析大型XML文件时,我的应用程序崩溃了 我在SO中发现了一个问题here没有答案 当我减小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)

HERE是我用来解析的代码

1 个答案:

答案 0 :(得分:1)

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

Ninja编辑:

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