Database error in logcat
i am working on an application and it works fine but in log i can see the below mentioned error: PLease suggest what could be the reason behind this and how to fix this.. I have closed all the cursors and also closing the database connection after use. PLease help...开发者_如何学C
12-02 17:16:48.500: ERROR/Database(388): close() was never explicitly called on database '/data/data/com.example.my/databases/my.db' 12-02 17:16:48.500: ERROR/Database(388): android.database.sqlite.DatabaseObjectNotClosedException: Application did not close the cursor or database object that was opened here 12-02 17:16:48.500: ERROR/Database(388): at android.database.sqlite.SQLiteDatabase.(SQLiteDatabase.java:1810) 12-02 17:16:48.500: ERROR/Database(388): at android.database.sqlite.SQLiteDatabase.openDatabase(SQLiteDatabase.java:817) 12-02 17:16:48.500: ERROR/Database(388): at android.database.sqlite.SQLiteDatabase.openOrCreateDatabase(SQLiteDatabase.java:851)
You need to close the database from your activity's onDestroy
method. Assuming that you've written your application using a "database helper" class, as in some Android tutorials such as Notepad, then this ought to work for you as-is. (Otherwise, just replace mDbHelper.close()
with the appropriate call to close your database connection.)
public class MyClass extends Activity {
// ...
@Override
protected void onDestroy() {
super.onDestroy();
mDbHelper.close();
}
}
精彩评论