【发布时间】:2014-07-06 15:47:23
【问题描述】:
我以前有一个数据库,没有错误,我的数据库来自asset文件夹,已经用SQLCipher编码了
之后,在我的所有活动中,我都会收到游标或数据库已打开但未关闭的错误。
@Override
protected void onCreate() {
super.onCreate();
myDb = new DBAdapter(this);
myDb.open();
cursor = myDb.getFavorits();
}
@Override
protected void onDestroy() {
super.onDestroy();
myDb.close();
cursor.close();
}
@Override
protected void onStop() {
super.onStop();
myDb.close();
cursor.close();
}
这是它打开和关闭的 DBAdapter 类:
public void open() {
SQLiteDatabase.loadLibs(context);
File databaseFile = context.getDatabasePath("mydb");
db = SQLiteDatabase.openOrCreateDatabase(databaseFile,"mypass", null);
}
public void close() {
Log.v("this","dbclose");
db.close();
}
public Cursor getFavorits() {
Cursor c = db.query(DATABASE_TABLE, ALL_KEYS, null, null, null, null,null, null);
if (c != null) {
c.moveToFirst();
}
return c;
}
但是当我离开这个活动时,它会告诉我这个错误:
Finalizing a Cursor that has not been deactivated or closed. database = /data/data/pachagename/databases/mydb, table = null, query = SELECT _id from favorits
07-06 15:42:42.769: E/Cursor(1214): net.sqlcipher.database.DatabaseObjectNotClosedException: Application did not close the cursor or database object that was opened here
您能帮我找出并解决这个问题吗?
更新: 我现在注意到一些新的东西,当我进入活动而不离开活动时,它显示了这个错误!我该怎么办 ?
【问题讨论】:
标签: android android-sqlite sqlcipher