I have this error on google play crash report and don’t know how fix it :
java.lang.IllegalStateException: Couldn't init cursor window
at android.database.CursorWindow.native_init(Native Method)
at android.database.CursorWindow.<init>(CursorWindow.java:41)
at android.database.sqlite.SQLiteCursor.fillWindow(SQLiteCursor.java:276)
at android.database.sqlite.SQLiteCursor.getCount(SQLiteCursor.java:268)
at android.database.AbstractCursor.moveToPosition(AbstractCursor.java:171)
at android.database.AbstractCursor.moveToFirst(AbstractCursor.java:248)
at com.jim2.UpdateService.restaureNotifications(UpdateService.java:274)
at com.jim2.helpers.Globals.updateWidgets(Globals.java:1011)
at com.jim2.helpers.Globals.onReceive(Globals.java:746)
at com.jim2.UpdateService$5.onSignalStrengthsChanged(UpdateService.java:747)
at android.telephony.PhoneStateListener$2.handleMessage(PhoneStateListener.java:387)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:130)
at android.app.ActivityThread.main(ActivityThread.java:3693)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:507)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:907)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:665)
at dalvik.system.NativeStart.main(Native Method)
Here is my code who have the crash :
DataBaseHelper d = new DataBaseHelper(context);
Cursor c = d.getNotifications(false);
SharedPreferences preferences;
String ns = Context.NOTIFICATION_SERVICE;
NotificationManager mNotificationManager = (NotificationManager)context.getSystemService(ns);
CharSequence tickerText = "";
if(c!=null && c.moveToFirst()){ // CRASH HERE :(
do{
....
while(c.moveToNext());
if(c!=null && !c.isClosed()) {
c.close();c = null;
}
}
d.close();
Here the code to get the cursor from getNotifications :
public Cursor getNotifications(boolean all) {
//removeAllNotifications();
Cursor c;
String fields[] = new String[] { "id", "ordre", "is_active"};
String where = "is_active = 1";
if(all)where = "";
c = myDataBase.query(TABLE, fields, where, null, null, null, "ordre");
return c;
}
My problem is i can’t reproduce the crash so it’s hard to fix cause on my devices all works correctly.
Already see this post Android: Couldn't init Cursor Window but me it crash on moveToFirst not later and i already add code in answer.
Thanks a lot
this exception is thrown by the native code. (refer to this)
mainly it is due to failing to allocate memory for the new cursor being created. so my guess is that the data you are fetching sometimes get too too much (nearly more than 1M in memory) or you are opening lots of cursor without closing them untill you ran out of memory to allocate a new buffer.
finallyclause.let me know if this helps.