当我进入另一个活动以将新项目插入数据库时,返回然后进入该活动,它给了我一个错误:
04-03 18:53:26.914: E/Database(18134): Leak found
04-03 18:53:26.914: E/Database(18134): java.lang.IllegalStateException: /data/data/com.app.myapp/databases/BabyApp.db SQLiteDatabase created and never closed
04-03 18:53:26.914: E/Database(18134): at android.database.sqlite.SQLiteDatabase.<init>(SQLiteDatabase.java:1695)
04-03 18:53:26.914: E/Database(18134): at android.database.sqlite.SQLiteDatabase.openDatabase(SQLiteDatabase.java:739)
04-03 18:53:26.914: E/Database(18134): at android.database.sqlite.SQLiteDatabase.openOrCreateDatabase(SQLiteDatabase.java:761)
04-03 18:53:26.914: E/Database(18134): at android.database.sqlite.SQLiteDatabase.openOrCreateDatabase(SQLiteDatabase.java:754)
04-03 18:53:26.914: E/Database(18134): at android.app.ApplicationContext.openOrCreateDatabase(ApplicationContext.java:473)
04-03 18:53:26.914: E/Database(18134): at android.content.ContextWrapper.openOrCreateDatabase(ContextWrapper.java:193)
04-03 18:53:26.914: E/Database(18134): at android.database.sqlite.SQLiteOpenHelper.getWritableDatabase(SQLiteOpenHelper.java:98)
04-03 18:53:26.914: E/Database(18134): at com.app.myapp.DatabaseHelper.open(DatabaseHelper.java:121)
04-03 18:53:26.914: E/Database(18134): at com.app.myapp.SettingsActivity.init(SettingsActivity.java:80)
这是 DatabaseHelper.java:121
database = dbHelper.getWritableDatabase();
这是 SettingsActivity 第 80 行代码:
if (!db.isOpen())
db.open();