Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
659 views
in Technique[技术] by (71.8m points)

android - How can one avoid DatabaseObjectNotClosedException

How one we avoid this exception??

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)
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

I think this error appears because you didn’t close your database. Always close your sqlitehelper class

EDITED:

You have to implement like this in your class which is extending SQLiteOpenHelper class:

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...