“打开的文件太多”错误 [英] 'Too many open files' error

查看:394
本文介绍了“打开的文件太多”错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的应用程序,有一个表单提交插入操作。大多数情况下,插入操作是成功的。有时,插入操作是不会发生,然后它给了java.lang.RuntimeException 。这里是logcat的细节:

In my app, there is an insert operation on a form submission. Most of the cases the insert operation is successful. Sometimes the insertion operation is not happening and then , it is giving java.lang.RuntimeException. Here is the logcat details:

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)

可能是什么问题,在我的code?

What may be the problem in my code?

推荐答案

很多时候(如trjanfoe建议),这些各种各样的问题,因为游标仍处于打开状态。我发现我可以使用的try /终于$ C $的cblock消除大部分的问题。

Very often (as trjanfoe suggested) these sorts of problems are because Cursors are still open. I've found that I can eliminate most of the problems by use try/finally codeblocks.

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

这确保光标将始终关闭,无论发生什么事情。

This ensures that the cursor will ALWAYS be closed, no matter what happens.

这篇关于“打开的文件太多”错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆