光标窗口分配4096 kb失败

时间:2016-10-21 09:07:48

标签: android database cursor

通常,当光标未关闭时会发生此错误,但就我而言,我正确地关闭它。这有什么问题?

日志:

    10-21 11:55:36.818 26541-26541/com.mycrosswod.crossfit E/CursorWindow: Could not allocate CursorWindow '/data/data/com.mycrosswod.crossfit/databases/Crossfit' of size 4194304 due to error -12.
    10-21 11:55:36.843 26541-26541/com.mycrosswod.crossfit D/AndroidRuntime: Shutting down VM
    10-21 11:55:36.843 26541-26541/com.mycrosswod.crossfit W/dalvikvm: threadid=1: thread exiting with uncaught exception (group=0x40c681f8)
    10-21 11:55:36.863 26541-26541/com.mycrosswod.crossfit E/AndroidRuntime: FATAL EXCEPTION: main
                                                                             java.lang.RuntimeException: Unable to start activity ComponentInfo{com.mycrosswod.crossfit/com.mycrosswod.crossfit.gui.WodsListActivity}: android.database.CursorWindowAllocationException: Cursor window allocation of 4096 kb failed. # Open Cursors=379 (# cursors opened by this proc=379)
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.mycrosswod.crossfit/com.mycrosswod.crossfit.gui.WodsListActivity}: android.database.CursorWindowAllocationException: Cursor window allocation of 4096 kb failed. # Open Cursors=378 (# cursors opened by this proc=378)

方法:

ArrayList<WodForBuilder> wods = new ArrayList<WodForBuilder>();

    Cursor cursor = database.query(MySQLiteHelper.WOD_TABLE,
            new String[]{"*"}, null, null, null, null, null);

    cursor.moveToFirst();
    while (!cursor.isAfterLast()) {
        WodForBuilder wod = cursorToWodWithRound(cursor);
        wods.add(wod);
        cursor.moveToNext();
    }
    // make sure to close the cursor
    if(cursor!=null) {
        cursor.close();
    }
    return wods;
}

1 个答案:

答案 0 :(得分:0)

错误代码是-12意味着游标泄漏,找到项目中使用的所有Cusor查询。检查它是否最后调用close(); 建议使用{{1}}