3

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

4
  • Is there any way you could use an SQLite database rather than an XML file for your data? Commented Nov 26, 2010 at 7:13
  • im parsing XML files and storing it to SqliteDB mate.! Commented Nov 26, 2010 at 7:15
  • 3
    I'm not sure if the parsing itself is causing it or the storing in the List<DbEntry> list simply becoming too big. If latter, try to directly push the data to the sqlite DB instead of storing it in the List<DbEntry>. May be less efficient, but with huge number of records maybe a better solution. Or cache 20-30 entries and flush them into the DB, clear the list and cache another 20-30 Commented Nov 26, 2010 at 9:51
  • Thanks mate,my List<DbEntry> was becoming huge..Problem solved.. Commented Nov 27, 2010 at 18:02

1 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.