gpt4 book ai didi

android - 尝试重新打开一个已经关闭的对象:SQLiteQuery

转载 作者:行者123 更新时间:2023-12-03 18:14:49 27 4
gpt4 key购买 nike

好吧,我迷路了,说“叔叔”。我收到“尝试重新打开已经关闭的对象:SQLiteQuery”错误消息-请参见下面的日志。如您所见,该错误发生在下面粘贴的方法中。工作正常。有趣的是,我只是在一个完整的其他方法中添加了一个cursor.close,在其中缺少一个方法,因为我收到了“ SQLite Android Database Cursor窗口分配的2048 kb失败”消息。

但是我不确定为什么该方法会开始引发错误? cursor.close始终位于同一位置,以前从未引起错误,并且显示正确。完全迷路了。

我看了下面的这些帖子,但据我所知我似乎做得正确。谢谢您的帮助!

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;

}


日志:

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)


编辑:已解决。在深夜,我看不到它是我向cursor.close添加的方法之一,这导致了问题。该方法调用cursorToDB_Row。我不喜欢在那儿关闭光标。

//assumes ID is column 0 and the main string (usually name) is 1
private dbData cursorToDB_Row(Cursor cursor, String myTable) {
dbData dbData = new dbData();
dbData.setId(cursor.getLong(0)); //Id column
dbData.setDbData(cursor.getString(1)); //primary string column
dbData.setTable(myTable);
//cursor.close();
return dbData;
}

最佳答案

解决了。到了深夜,我看不到它是其中一种方法(我将cursor.close添加到该方法中)导致了问题。该方法调用cursorToDB_Row。我不喜欢在那儿关闭光标。我将其注释掉,如下所示,它确实有效。

//assumes ID is column 0 and the main string (usually name) is 1
private dbData cursorToDB_Row(Cursor cursor, String myTable) {
dbData dbData = new dbData();
dbData.setId(cursor.getLong(0)); //Id column
dbData.setDbData(cursor.getString(1)); //primary string column
dbData.setTable(myTable);
//cursor.close();
return dbData;
}

关于android - 尝试重新打开一个已经关闭的对象:SQLiteQuery,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29191253/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com