我尝试在Android上为我的应用程序使用H2,其中一个主表是:
创建表,如果不是EXISTS" +" tbl_content(" +" date DATE PRIMARY KEY," +" content OTHER);
当我向其添加数据时,在向该表插入一些数据后,我得到以下错误:
我多次更改我的代码(更改读取文件,我也拆分我的文件等等......)但没有任何改变,每次我一次又一次地收到此错误:java.lang.OutOfMemoryError: Capacity:
我还将android:largeHeap="true"
添加到清单文件,但没有任何改变!!!
03-28 15:46:44.786 9512-11006/? D/dalvikvm﹕ GC_BEFORE_OOM freed 81K, 27% free 12064K/16316K, paused 84ms, total 85ms
03-28 15:46:44.786 9512-11006/? E/dalvikvm-heap﹕ Out of memory on a 2097168-byte allocation.
03-28 15:46:44.796 9512-11006/? I/dalvikvm﹕ "MVStore background writer nio:/data/data/com.example.me/files/dbx.mv.db" daemon prio=5 tid=14 RUNNABLE
03-28 15:46:44.796 9512-11006/? I/dalvikvm﹕ | group="main" sCount=0 dsCount=0 obj=0xb4fbe238 self=0xb8714e70
03-28 15:46:44.796 9512-11006/? I/dalvikvm﹕ | sysTid=11006 nice=0 sched=0/0 cgrp=apps handle=-1200532792
03-28 15:46:44.796 9512-11006/? I/dalvikvm﹕ | state=R schedstat=( 4230000000 770000000 168 ) utm=412 stm=11 core=0
03-28 15:46:44.796 9512-11006/? I/dalvikvm﹕ at java.nio.ByteBuffer.allocate(ByteBuffer.java:~56)
03-28 15:46:44.796 9512-11006/? I/dalvikvm﹕ at org.h2.mvstore.WriteBuffer.grow(WriteBuffer.java:308)
03-28 15:46:44.816 9512-11006/? I/dalvikvm﹕ at org.h2.mvstore.WriteBuffer.ensureCapacity(WriteBuffer.java:295)
03-28 15:46:44.816 9512-11006/? I/dalvikvm﹕ at org.h2.mvstore.WriteBuffer.put(WriteBuffer.java:157)
03-28 15:46:44.816 9512-11006/? I/dalvikvm﹕ at org.h2.mvstore.db.ValueDataType.writeValue(ValueDataType.java:289)
03-28 15:46:44.826 9512-11006/? I/dalvikvm﹕ at org.h2.mvstore.db.ValueDataType.writeValue(ValueDataType.java:381)
03-28 15:46:44.826 9512-11006/? I/dalvikvm﹕ at org.h2.mvstore.db.ValueDataType.write(ValueDataType.java:189)
03-28 15:46:44.826 9512-11006/? I/dalvikvm﹕ at org.h2.mvstore.db.TransactionStore$VersionedValueType.write(TransactionStore.java:1695)
03-28 15:46:44.826 9512-11006/? I/dalvikvm﹕ at org.h2.mvstore.Page.write(Page.java:737)
03-28 15:46:44.826 9512-11006/? I/dalvikvm﹕ at org.h2.mvstore.Page.writeUnsavedRecursive(Page.java:818)
03-28 15:46:44.836 9512-11006/? I/dalvikvm﹕ at org.h2.mvstore.Page.writeUnsavedRecursive(Page.java:824)
03-28 15:46:44.836 9512-11006/? I/dalvikvm﹕ at org.h2.mvstore.MVStore.storeNowTry(MVStore.java:1060)
03-28 15:46:44.836 9512-11006/? I/dalvikvm﹕ at org.h2.mvstore.MVStore.storeNow(MVStore.java:976)
03-28 15:46:44.836 9512-11006/? I/dalvikvm﹕ at org.h2.mvstore.MVStore.commitAndSave(MVStore.java:965)
03-28 15:46:44.836 9512-11006/? I/dalvikvm﹕ at org.h2.mvstore.MVStore.writeInBackground(MVStore.java:2373)
03-28 15:46:44.836 9512-11006/? I/dalvikvm﹕ at org.h2.mvstore.MVStore$BackgroundWriterThread.run(MVStore.java:2586)
03-28 15:46:44.836 9512-11006/? I/dalvikvm﹕ [ 03-28 15:46:44.836 9512:11006 W/dalvikvm ]
threadid=14: thread exiting with uncaught exception (group=0xb4aaaba8)
03-28 15:46:44.866 9512-11006/? E/AndroidRuntime﹕ FATAL EXCEPTION: MVStore background writer nio:/data/data/com.example.me/files/dbx.mv.db
Process: com.example.me, PID: 9512
java.lang.OutOfMemoryError: Capacity: 2097152
at org.h2.mvstore.WriteBuffer.grow(WriteBuffer.java:310)
at org.h2.mvstore.WriteBuffer.ensureCapacity(WriteBuffer.java:295)
at org.h2.mvstore.WriteBuffer.put(WriteBuffer.java:157)
at org.h2.mvstore.db.ValueDataType.writeValue(ValueDataType.java:289)
at org.h2.mvstore.db.ValueDataType.writeValue(ValueDataType.java:381)
at org.h2.mvstore.db.ValueDataType.write(ValueDataType.java:189)
at org.h2.mvstore.db.TransactionStore$VersionedValueType.write(TransactionStore.java:1695)
at org.h2.mvstore.Page.write(Page.java:737)
at org.h2.mvstore.Page.writeUnsavedRecursive(Page.java:818)
at org.h2.mvstore.Page.writeUnsavedRecursive(Page.java:824)
at org.h2.mvstore.MVStore.storeNowTry(MVStore.java:1060)
at org.h2.mvstore.MVStore.storeNow(MVStore.java:976)
at org.h2.mvstore.MVStore.commitAndSave(MVStore.java:965)
at org.h2.mvstore.MVStore.writeInBackground(MVStore.java:2373)
at org.h2.mvstore.MVStore$BackgroundWriterThread.run(MVStore.java:2586)
03-28 15:46:44.916 413-680/? W/ActivityManager﹕ Force finishing activity com.example.me/.view.SettingsActivity
03-28 15:46:45.856 9512-9512/? I/Choreographer﹕ Skipped 49 frames! The application may be doing too much work on its main thread.
03-28 15:46:46.316 9512-9512/? W/EGL_emulation﹕ eglSurfaceAttrib not implemented
03-28 15:46:48.576 9512-9512/? E/WindowManager﹕ android.view.WindowLeaked: Activity com.example.me.view.SettingsActivity has leaked window com.android.internal.policy.impl.PhoneWindow$DecorView{b51f0f90 V.E..... R....... 0,0-320,140} that was originally added here
at android.view.ViewRootImpl.<init>(ViewRootImpl.java:348)
at android.view.WindowManagerGlobal.addView(WindowManagerGlobal.java:248)
at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:69)
at android.app.Dialog.show(Dialog.java:286)
at com.example.me.util.Updater.onPreExecute(Updater.java:60)
at android.os.AsyncTask.executeOnExecutor(AsyncTask.java:587)
at android.os.AsyncTask.execute(AsyncTask.java:535)
at com.example.me.util.Downloader.onPostExecute(Downloader.java:161)
at com.example.me.util.Downloader.onPostExecute(Downloader.java:18)
at android.os.AsyncTask.finish(AsyncTask.java:632)
at android.os.AsyncTask.access$600(AsyncTask.java:177)
at android.os.AsyncTask$InternalHandler.handleMessage(AsyncTask.java:645)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:136)
at android.app.ActivityThread.main(ActivityThread.java:5017)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
at dalvik.system.NativeStart.main(Native Method)
答案 0 :(得分:0)
这不是H2问题,这个错误来自app的其他部分,因为堆大小很小,我尝试读取文件的大块并将其插入数据库,我在读取文件和所有内容时更改程序逻辑效果很好。