SQLCipher - 完成尚未停用的游标错误

时间:2011-12-29 19:47:04

标签: android sqlite cursor

我的问题与此one非常相似,但略有不同。当我只是尝试查询我的表中已由SQLCiper加密的所有内容时,我收到以下错误。

 12-29 11:37:54.329: E/Cursor(10837): Finalizing a Cursor that has not been deactivated or closed. database = /data/data/com.company.myapp/databases/data, table = data_table, query = SELECT rowid, data FROM data_table
 12-29 11:37:54.329: E/Cursor(10837): info.guardianproject.database.sqlcipher.DatabaseObjectNotClosedException: Application did not close the cursor or database object that was opened here
 12-29 11:37:54.329: E/Cursor(10837):   at info.guardianproject.database.sqlcipher.SQLiteCursor.<init>(SQLiteCursor.java:225)
 12-29 11:37:54.329: E/Cursor(10837):   at info.guardianproject.database.sqlcipher.SQLiteDirectCursorDriver.query(SQLiteDirectCursorDriver.java:53)
 12-29 11:37:54.329: E/Cursor(10837):   at info.guardianproject.database.sqlcipher.SQLiteDatabase.rawQueryWithFactory(SQLiteDatabase.java:1410)
 12-29 11:37:54.329: E/Cursor(10837):   at info.guardianproject.database.sqlcipher.SQLiteDatabase.queryWithFactory(SQLiteDatabase.java:1289)
 12-29 11:37:54.329: E/Cursor(10837):   at info.guardianproject.database.sqlcipher.SQLiteDatabase.query(SQLiteDatabase.java:1243)
 12-29 11:37:54.329: E/Cursor(10837):   at info.guardianproject.database.sqlcipher.SQLiteDatabase.query(SQLiteDatabase.java:1325)
 12-29 11:37:54.329: E/Cursor(10837):   at com.company.appName.DatabaseManager.queryAllItems(DatabaseManager.java:105)

我认为只有在我完成使用后忘记关闭Cursor时才会出现此错误,但似乎即使在我开始使用它之前我也会收到此错误。< / p>

以下是queryAllItems()方法中的代码:

public Cursor queryAllItems() {
    return database.query(DATABASE_TABLE, new String[] {KEY_ID, KEY_DATA}, null, null, null, null, null);
}

2 个答案:

答案 0 :(得分:1)

我被堆栈跟踪误导了,看来我只需要在完成对查询的所有操作后调用Cursor.deactivate()Cursor.close()

答案 1 :(得分:0)

创建光标后,如果致电startManagingCursor(c);将解决问题。这里'c'是游标引用。