2011-01-19 22 views
2

我们如何避免这种异常?如何避免DatabaseObjectNotClosedException

 
01-19 17:16:16.024: WARN/SQLiteCompiledSql(477): Releasing statement in a finalizer. Please ensure that you explicitly call close() on your cursor: SELECT * FROM test 

01-19 17:16:16.024: WARN/SQLiteCompiledSql(477): android.database.sqlite.DatabaseObjectNotClosedException: Application did not close the cursor or database object that was opened here 

01-19 17:16:16.024: WARN/SQLiteCompiledSql(477): android.database.sqlite.DatabaseObjectNotClosedException: Application did not close the cursor or database object that was opened here 

01-19 17:16:16.024: WARN/SQLiteCompiledSql(477):  at android.database.sqlite.SQLiteCompiledSql.(SQLiteCompiledSql.java:62) 

01-19 17:16:16.024: WARN/SQLiteCompiledSql(477):  at android.database.sqlite.SQLiteProgram.(SQLiteProgram.java:80) 

01-19 17:16:16.024: WARN/SQLiteCompiledSql(477):  at android.database.sqlite.SQLiteQuery.(SQLiteQuery.java:46) 

回答

5

我觉得这个错误是因为你没有关闭你的数据库。始终关闭sqlitehelper类

编辑:

您必须实现这样在你的类,这是扩展SQLiteOpenHelper类:上

@Override 
public synchronized void close() { 
    if(db != null){ 
     db.close(); 
    super.close(); 
    } 
} 
+0

其中i关闭cursor..after所有的数据库操作。或者在OnDestroy..pls帮助 – jennifer 2011-01-21 05:05:38

3

好,因为它说,调用close()你的光标!

1

我也得到了异常,当我有一个错误的SQL查询使用游标时。这听起来很愚蠢,但如果有人发现同样的,它的另一个原因......

0

我解决了异常。我打电话

db = eventsData.getReadableDatabase(); 

两次这就是为什么抛出异常