java.lang.RuntimeException: Unable to start activity ComponentInfo{com.ecomtrading.kitekoLite/com.ecomtrading.kitekoLite.activities.MainMenuActivity}: android.database.CursorWindowAllocationException: Could not allocate CursorWindow '/storage/emulated/0/KitekoLite/Dev/0271154324/.db/KitekoLite.db' of size 4194304 due to error -12.
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3556)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3703)
at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:83)
at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135)
at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2216)
at android.os.Handler.dispatchMessage(Handler.java:107)
at android.os.Looper.loop(Looper.java:237)
at android.app.ActivityThread.main(ActivityThread.java:7948)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1075)
Caused by: android.database.CursorWindowAllocationException: Could not allocate CursorWindow '/storage/emulated/0/KitekoLite/Dev/0271154324/.db/KitekoLite.db' of size 4194304 due to error -12.
at android.database.CursorWindow.nativeCreate(Native Method)
at android.database.CursorWindow.<init>(CursorWindow.java:145)
at android.database.sqlite.SQLiteCursor.clearOrCreateWindow(SQLiteCursor.java:319)
at android.database.sqlite.SQLiteCursor.fillWindow(SQLiteCursor.java:159)
at android.database.sqlite.SQLiteCursor.getCount(SQLiteCursor.java:152)
at android.database.AbstractCursor.moveToPosition(AbstractCursor.java:232)
at android.database.AbstractCursor.moveToFirst(AbstractCursor.java:271)
at com.orm.SugarRecord.runCustomQuery(SugarRecord.java:50)
at com.orm.SugarRecord.runCustomQuery(SugarRecord.java:42)
at com.example.core.utils.Utils.isScreenAvailable(Utils.java:571)
at com.ecomtrading.kitekoLite.common.ScreenHelper.hasScreenAccess(ScreenHelper.java:52)
at com.ecomtrading.kitekoLite.common.ScreenHelper.hasCustomerAccess(ScreenHelper.java:35)
at com.ecomtrading.kitekoLite.common.ScreenHelper.hasModuleAccess(ScreenHelper.java:15)
at com.ecomtrading.kitekoLite.activities.MainMenuActivity.loadScreens(MainMenuActivity.java:230)
at com.ecomtrading.kitekoLite.activities.MainMenuActivity.setUpNavigationView(MainMenuActivity.java:218)
at com.ecomtrading.kitekoLite.activities.MainMenuActivity.onCreate(MainMenuActivity.java:106)
at android.app.Activity.performCreate(Activity.java:7955)
at android.app.Activity.performCreate(Activity.java:7944)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1307)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3531)
... 11 more
I have been getting this crash in my application. So I intended to use StrictMode.VmPolicy library to detect any unclosed cursors but it detects wrongly for me. For example, I am using a sugar db library that and the library detects a penalty there as the cursor is not closed. Even though the cursor is not closed but I use try-with-resource to close it after using the cursor returned from the sugar library.
public static Cursor runCustomQuery(String sql)
{
return runCustomQuery(sql,true);
}
public static Cursor runCustomQuery(String sql, boolean movefirst)
{
Cursor c = getSugarDataBase().rawQuery(sql,null);
if(movefirst) {
c.moveToFirst();
}
return c;
}
After that I use try-with-resource to close it like this
public static Boolean isScreenAvailable(FormDataType formDataType) {
Boolean screenavailability = false;
if(formDataType!=null) {
try (Cursor screencode = Screens.runCustomQuery("Select menuitemcode from Screens where menuitemcode='" + formDataType.getNumber() + "' and status='A'")) {
if (screencode.moveToFirst()) {
screenavailability = true;
}
}
}
return screenavailability;
}
I have been using try-with-resource for all my autoCloseables but I am still getting CursorWindowAllocationException. Please, any help will be much appreciated. Another question is will try-with-resource close the cursor? Because I am using try with resource and still get above exception
I want to understand this exception, Could not allocate CursorWindow '/storage/emulated/0/KitekoLite/Dev/0271154324/.db/KitekoLite.db' of size 4194304 due to error -12 and what does error -12 means?
I tried searching through my codes to see if I have laid open any cursor but I cannot see such but sometimes this above exception will be thrown.