在kitkat中,我可以毫无问题地运行此代码:
mDb = getDatabaseHelper().getWritableDatabase();
mDb.beginTransactionWithListener(this);
try {
count = updateInTransaction(uri, values, selection, selectionArgs);
if (count > 0) {
mNotifyChange = true;
}
mDb.setTransactionSuccessful();
} finally {
mDb.endTransaction();
}
但是在棒棒糖上我得到了这个奇怪的错误:
03-11 16:05:33.275 1947-2326/nl.afas.pocket E/SQLiteLog﹕ (11) database corruption at line 57126 of [9491ba7d73]
03-11 16:05:33.275 1947-2326/nl.afas.pocket E/SQLiteLog﹕ (11) statement aborts at 54: [UPDATE Contact SET favorite=?,_id=? WHERE _id = ?]
03-11 16:05:33.275 1947-2326/nl.afas.pocket E/DefaultDatabaseErrorHandler﹕ Corruption reported by sqlite on database: /data/data/nl.afas.pocket/databases/pocket.db
03-11 16:05:33.275 1947-2326/nl.afas.pocket E/DefaultDatabaseErrorHandler﹕ deleting the database file: /data/data/nl.afas.pocket/databases/pocket.db
03-11 16:05:33.278 1947-2326/nl.afas.pocket E/AndroidRuntime﹕ FATAL EXCEPTION: Thread-141
Process: nl.afas.pocket, PID: 1947
java.lang.IllegalStateException: attempt to re-open an already-closed object: SQLiteDatabase: /data/data/nl.afas.pocket/databases/pocket.db
at android.database.sqlite.SQLiteClosable.acquireReference(SQLiteClosable.java:55)
at android.database.sqlite.SQLiteDatabase.endTransaction(SQLiteDatabase.java:520)
at nl.afas.pocket.content.SQLiteContentProvider.update(SQLiteContentProvider.java:144)
updateInTransaction
发生第一个错误(数据库损坏)第二个错误的illigal状态异常发生在mDb.endTransaction(); mDb已经关闭..
在KitKat中,不会在完全相同的数据库上抛出错误。
答案 0 :(得分:1)
对于带有索引的数据库,我遇到了同样的问题。
删除了索引,问题解决了。 (我正在运行Lollipop模拟器)。