samedi 21 mars 2015

attempt to re-open an already-closed object: SQLiteQuery

Okay, I'm lost and saying 'uncle.' I'm getting the 'attempt to re-open an already-closed object: SQLiteQuery' error message - see log below. As you can see the error occurs in the method pasted below. It was working fine. Interestingly enough, I just added a cursor.close to a complete other method where it was missing one because I was getting a 'SQLite Android Database Cursor window allocation of 2048 kb failed' message.


But I'm not sure why this method would start throwing an error? The cursor.close has always been in the same location, never caused an error before, and appears correct. Completely lost.


I looked at these posts below, but I seem to be doing things correctly as far as I can tell. Thanks for the help!


Android - attempt to re-open an already-closed object: SQLiteQuery using loaderManager


attempt to reopen an already-closed object: sqlitequery



public List<dbData> queryToList(String myTable, String[] myColumns, String whereClause,
String[] whereArgs, String groupBy, String having, String orberBy) {
System.out.println("start queryToList");
List<dbData> dbDatas = new ArrayList<>();

Cursor cursor = database.query(myTable, myColumns,
whereClause, whereArgs, groupBy, having, orberBy);
System.out.println("cursor count = " + cursor.getCount());
cursor.moveToFirst();
while (!cursor.isAfterLast()) {
dbData dbData = cursorToDB_Row(cursor, myTable);
dbData.setIntTemp1(0);
dbDatas.add(dbData);
cursor.moveToNext();
}
// make sure to close the cursor
cursor.close();
return dbDatas;

}


Log:



03-21 21:51:44.695 9457-9457/com.mycompany.dudesmyreminders I/System.out﹕ start changeReminder
03-21 21:51:44.695 9457-9457/com.mycompany.dudesmyreminders I/System.out﹕ start Reminder
03-21 21:51:44.695 9457-9457/com.mycompany.dudesmyreminders I/System.out﹕ savePreference for reminder
03-21 21:51:44.695 9457-9457/com.mycompany.dudesmyreminders I/System.out﹕ start determineReminder
03-21 21:51:44.695 9457-9457/com.mycompany.dudesmyreminders I/System.out﹕ start relationshipSpace
03-21 21:51:44.695 9457-9457/com.mycompany.dudesmyreminders I/System.out﹕ start queryToList
03-21 21:51:44.705 9457-9457/com.mycompany.dudesmyreminders I/System.out﹕ cursor count = 110
03-21 21:51:44.705 9457-9457/com.mycompany.dudesmyreminders E/AndroidRuntime﹕ FATAL EXCEPTION: main
Process: com.mycompany.dudesmyreminders, PID: 9457
java.lang.IllegalStateException: attempt to re-open an already-closed object: SQLiteQuery: SELECT * FROM reminders
at android.database.sqlite.SQLiteClosable.acquireReference(SQLiteClosable.java:55)
at android.database.sqlite.SQLiteQuery.fillWindow(SQLiteQuery.java:58)
at android.database.sqlite.SQLiteCursor.fillWindow(SQLiteCursor.java:178)
at android.database.sqlite.SQLiteCursor.onMove(SQLiteCursor.java:150)
at android.database.AbstractCursor.moveToPosition(AbstractCursor.java:214)
at android.database.AbstractCursor.moveToNext(AbstractCursor.java:245)
at com.mycompany.dudesmyreminders.dbDataSource.queryToList(dbDataSource.java:147)
at com.mycompany.dudesmyreminders.Reminder.relationshipSpace(Reminder.java:104)
at com.mycompany.dudesmyreminders.Reminder.determineReminder(Reminder.java:83)
at com.mycompany.dudesmyreminders.MainActivity.changeReminder(MainActivity.java:144)
at com.mycompany.dudesmyreminders.MainActivity.onOptionsItemSelected(MainActivity.java:97)
at android.app.Activity.onMenuItemSelected(Activity.java:2907)
at android.support.v4.app.FragmentActivity.onMenuItemSelected(FragmentActivity.java:350)
at android.support.v7.app.ActionBarActivity.onMenuItemSelected(ActionBarActivity.java:155)
at android.support.v7.app.ActionBarActivityDelegate$1.onMenuItemSelected(ActionBarActivityDelegate.java:74)
at android.support.v7.app.ActionBarActivityDelegateBase.onMenuItemSelected(ActionBarActivityDelegateBase.java:556)
at android.support.v7.internal.view.menu.MenuBuilder.dispatchMenuItemSelected(MenuBuilder.java:802)
at android.support.v7.internal.view.menu.MenuItemImpl.invoke(MenuItemImpl.java:153)
at android.support.v7.internal.view.menu.MenuBuilder.performItemAction(MenuBuilder.java:949)
at android.support.v7.internal.view.menu.MenuBuilder.performItemAction(MenuBuilder.java:939)
at android.support.v7.widget.ActionMenuView.invokeItem(ActionMenuView.java:596)
at android.support.v7.internal.view.menu.ActionMenuItemView.onClick(ActionMenuItemView.java:145)
at android.view.View.performClick(View.java:4785)
at android.view.View$PerformClick.run(View.java:19858)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:155)
at android.app.ActivityThread.main(ActivityThread.java:5696)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1028)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:823)

Aucun commentaire:

Enregistrer un commentaire