java.lang.IllegalStateException: Couldn't init cursor window at android.database.CursorWindow.native_init(Native Method) at android.database.CursorWindow.After few hours of googling, I found the solution to this problem. Solution is to close the Cursor after after you are done!This exception is thrown here(CursorWindow.java:41) at android.database.sqlite.SQLiteCursor.fillWindow(SQLiteCursor.java:277) at android.database.sqlite.SQLiteCursor.getCount(SQLiteCursor.java:269)
localOnly is defined inif (!window->initBuffer(localOnly)) { jniThrowException(env, "java/lang/IllegalStateException", "Couldn't init cursor window"); delete window; return; }
CursorWindow.has
#define MAX_WINDOW_SIZE (1024 * 1024)So, There are two possible causes to throw this exception. 1. Your mobile phone is out of memory.2. You are fetching something out of the database more than 1M. If there is a logical way to divide your queries into discrete chunks, you could do incremental queries and use CursorJoiner to stitch them together that might help you if you are dealing with big chuck of data.
So lesson learned, Close the cursor in a try finally block
Cursor cursor;
try {
cursor.open();
}
finally{
if(cursor.isOpen()) {
cursor.close();
}
Nice post
ReplyDeletebut this didn't resolved my issue.
Still i am getting the error message as
"java.lang.IllegalStateException: Couldn''t init cursor window"
Is there another way to resolve this?
Limited file is no more than 1Mb in database?, i have problem is query a file 2mb from dstabse
ReplyDelete