こんにちは私は以下のコードでxmlを解析しています
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
InputStream is = getResources().openRawResource(R.raw.bd);
try {
DocumentBuilder docBuilder = DocumentBuilderFactory.newInstance().newDocumentBuilder();
Document doc = docBuilder.parse(is, null);
doc.getDocumentElement().normalize();
NodeList my_words = doc.getElementsByTagName("word");
for (int i = 0; i < 100; i++) {
System.out.println(((Element) my_words.item(i)).getAttribute("eng"));
System.out.println(((Element) my_words.item(i)).getAttribute("guj"));
}
is.close();
} catch (Exception e) {
e.printStackTrace();
}
}
しかし、私は以下のようなエラーが発生しています...
01-11 16:00:48.709: E/dalvikvm-heap(18535): Out of memory on a 176-byte allocation.
01-11 16:00:48.709: I/dalvikvm(18535): "main" prio=5 tid=1 RUNNABLE
01-11 16:00:48.709: I/dalvikvm(18535): | group="main" sCount=0 dsCount=0 obj=0x40022190 self=0xd018
01-11 16:00:48.709: I/dalvikvm(18535): | sysTid=18535 nice=0 sched=0/0 cgrp=[fopen-error:2] handle=-1345002400
01-11 16:00:48.709: I/dalvikvm(18535): at java.lang.Throwable.nativeFillInStackTrace(Native Method)
01-11 16:00:48.709: I/dalvikvm(18535): at java.lang.Throwable.fillInStackTrace(Throwable.java:135)
01-11 16:00:48.709: I/dalvikvm(18535): at java.lang.Throwable.<init>(Throwable.java:74)
01-11 16:00:48.709: I/dalvikvm(18535): at java.lang.Error.<init>(Error.java:38)
01-11 16:00:48.709: I/dalvikvm(18535): at java.lang.VirtualMachineError.<init>(VirtualMachineError.java:36)
01-11 16:00:48.709: I/dalvikvm(18535): at java.lang.OutOfMemoryError.<init>(OutOfMemoryError.java:34)
01-11 16:00:48.709: I/dalvikvm(18535): at java.util.ArrayList.add(ArrayList.java:-1)
01-11 16:00:48.709: I/dalvikvm(18535): at org.apache.harmony.xml.dom.ElementImpl.setAttributeNode(ElementImpl.java:329)
01-11 16:00:48.709: I/dalvikvm(18535): at org.apache.harmony.xml.parsers.DocumentBuilderImpl.parse(DocumentBuilderImpl.java:355)
01-11 16:00:48.709: I/dalvikvm(18535): at org.apache.harmony.xml.parsers.DocumentBuilderImpl.parse(DocumentBuilderImpl.java:360)
01-11 16:00:48.709: I/dalvikvm(18535): at org.apache.harmony.xml.parsers.DocumentBuilderImpl.parse(DocumentBuilderImpl.java:133)
01-11 16:00:48.709: I/dalvikvm(18535): at javax.xml.parsers.DocumentBuilder.parse(DocumentBuilder.java:132)
01-11 16:00:48.709: I/dalvikvm(18535): at com.example.simplexmlpullapp.MainActivity.onCreate(MainActivity.java:32)
01-11 16:00:48.709: I/dalvikvm(18535): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
01-11 16:00:48.709: I/dalvikvm(18535): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1722)
01-11 16:00:48.709: I/dalvikvm(18535): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1784)
01-11 16:00:48.709: I/dalvikvm(18535): at android.app.ActivityThread.access$1500(ActivityThread.java:123)
01-11 16:00:48.709: I/dalvikvm(18535): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:939)
01-11 16:00:48.709: I/dalvikvm(18535): at android.os.Handler.dispatchMessage(Handler.java:99)
01-11 16:00:48.709: I/dalvikvm(18535): at android.os.Looper.loop(Looper.java:130)
01-11 16:00:48.709: I/dalvikvm(18535): at android.app.ActivityThread.main(ActivityThread.java:3835)
01-11 16:00:48.709: I/dalvikvm(18535): at java.lang.reflect.Method.invokeNative(Native Method)
01-11 16:00:48.709: I/dalvikvm(18535): at java.lang.reflect.Method.invoke(Method.java:507)
01-11 16:00:48.709: I/dalvikvm(18535): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:864)
01-11 16:00:48.709: I/dalvikvm(18535): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:622)
01-11 16:00:48.709: I/dalvikvm(18535): at dalvik.system.NativeStart.main(Native Method)
01-11 16:00:48.729: W/dalvikvm(18535): Exception thrown (Ljava/lang/OutOfMemoryError;) while throwing internal exception (Ljava/lang/OutOfMemoryError;)
01-11 16:00:48.729: W/dalvikvm(18535): Could not resolve class ref'ed in exception catch list (class index 349, exception Ljava/lang/OutOfMemoryError;)
01-11 16:00:49.209: I/dalvikvm-heap(18535): Clamp target GC heap from 25.906MB to 24.000MB
01-11 16:00:49.209: D/dalvikvm(18535): GC_CONCURRENT freed <1K, 11% free 22006K/24519K, external 3K/514K, paused 5ms+6ms
01-11 16:00:49.509: D/dalvikvm(18535): GC_FOR_MALLOC freed 19308K, 89% free 2698K/24519K, external 3K/514K, paused 294ms
01-11 16:00:49.509: D/AndroidRuntime(18535): Shutting down VM
01-11 16:00:49.509: W/dalvikvm(18535): threadid=1: thread exiting with uncaught exception (group=0x40018560)
01-11 16:00:49.509: E/AndroidRuntime(18535): FATAL EXCEPTION: main
01-11 16:00:49.509: E/AndroidRuntime(18535): java.lang.OutOfMemoryError: [memory exhausted]
01-11 16:00:49.509: E/AndroidRuntime(18535): at dalvik.system.NativeStart.main(Native Method)