在我的一个自定义数据库处理程序中,我收到此错误:
java.lang.IllegalStateException: attempt to re-open an already-closed object: /data/data/com.sample/databases/sample {0}
at android.database.sqlite.SQLiteClosable.acquireReference(SQLiteClosable.java:55)
在谷歌和本网站上的任何搜索之后我都找不到这段代码的问题:
public String getFirstItemReceived(String username){
db = this.getReadableDatabase ();
String mLastID = "";
String query = "SELECT * from "+ this.RECEIVE_FIELDS_TABLE +" WHERE userID = '"+username+"' ORDER BY lastId DESC";
cursor = db.rawQuery(query, null);
cursor.moveToFirst ();
if (cursor.moveToFirst()) {
mLastID = cursor.getString(cursor.getColumnIndex("lastId"));
}
cursor.close ();
return mLastID;
}
答案 0 :(得分:0)
您是否曾使用SQLiteDatabase.openDatabase(SDCARD_DB_PATH, null, SQLiteDatabase.OPEN_READWRITE)
访问数据库功能?并尝试打开光标。试试吧。
答案 1 :(得分:0)
我建议您使用Singleton Pattern样式更改“如何访问数据库”以避免出现错误
您可以从这些博客中了解如何执行此操作
http://www.androiddesignpatterns.com/2012/05/correctly-managing-your-sqlite-database.html