1

在我的应用程序中,表单提交有一个插入操作。大多数情况下插入操作是成功的。有时插入操作没有发生,然后,它正在给予java.lang.RuntimeException。这是logcat的详细信息:

03-28 10:52:09.260: ERROR/IMemory(1501): cannot dup fd=1023, size=1048576, err=0 (Too many open files)
03-28 10:52:09.260: ERROR/IMemory(1501): cannot map BpMemoryHeap (binder=0x5919b0), size=1048576, fd=-1 (Bad file number)
03-28 10:52:09.260: ERROR/JavaBinder(1501): *** Uncaught remote exception!  (Exceptions are not yet supported across processes.)
03-28 10:52:09.260: ERROR/JavaBinder(1501): java.lang.RuntimeException: No memory in memObj
03-28 10:52:09.260: ERROR/JavaBinder(1501):     at android.database.CursorWindow.native_init(Native Method)
03-28 10:52:09.260: ERROR/JavaBinder(1501):     at android.database.CursorWindow.<init>(CursorWindow.java:518)
03-28 10:52:09.260: ERROR/JavaBinder(1501):     at android.database.CursorWindow.<init>(CursorWindow.java:27)
03-28 10:52:09.260: ERROR/JavaBinder(1501):     at android.database.CursorWindow$1.createFromParcel(CursorWindow.java:493)
03-28 10:52:09.260: ERROR/JavaBinder(1501):     at android.database.CursorWindow$1.createFromParcel(CursorWindow.java:496)
03-28 10:52:09.260: ERROR/JavaBinder(1501):     at android.content.ContentProviderNative.onTransact(ContentProviderNative.java:96)
03-28 10:52:09.260: ERROR/JavaBinder(1501):     at android.os.Binder.execTransact(Binder.java:287)
03-28 10:52:09.260: ERROR/JavaBinder(1501):     at dalvik.system.NativeStart.run(Native Method)

我的代码中可能有什么问题?

4

1 回答 1

2

很多时候(正如 trjanfoe 所建议的)这类问题是因为光标仍然打开。我发现我可以通过使用 try/finally 代码块来消除大部分问题。

Cursor cursor = null;
try {
    cursor = db.insert(...);
    more code here
}
finally {
    if (cursor != null) {
        cursor.close();
        cursor = null;
    }
}

这确保了无论发生什么,游标都将始终关闭。

于 2012-05-06T17:22:26.193 回答