在我的应用程序中,我在很多情况下都使用 DB,但在一种情况下,我遇到了异常,不是每次都可以重现它(还)。
这仅在操作系统版本 2.3.7 和 2.1-update-1 上发生。
编码:
public void removeOldOccurrences() {
SQLiteDatabase db = dbHelper.getWritableDatabase();
Long oldTime = System.currentTimeMillis() - VALID_OCCURRENCE_TIME;
String query = "";
try {
query = "DELETE FROM " + LOCATIONS_TABLE + " WHERE not ("
+ REMEMBERED_FIELD + "=1) " + "and (" + LAST_FIELD + "<"
+ oldTime + ");";
db.execSQL(query);
} catch (Exception e) {
Log.e(TAG, query);
e.printStackTrace();
} finally {
if (db != null) {
db.close();
}
}
}
异常跟踪是:
android.database.sqlite.SQLiteException: not an error
at android.database.sqlite.SQLiteDatabase.dbopen(Native Method)
at android.database.sqlite.SQLiteDatabase.(SQLiteDatabase.java:1849)
at android.database.sqlite.SQLiteDatabase.openDatabase(SQLiteDatabase.java:820)
at android.database.sqlite.SQLiteDatabase.openOrCreateDatabase(SQLiteDatabase.java:854)
at android.database.sqlite.SQLiteDatabase.openOrCreateDatabase(SQLiteDatabase.java:847)
at android.app.ContextImpl.openOrCreateDatabase(ContextImpl.java:573)
at android.content.ContextWrapper.openOrCreateDatabase(ContextWrapper.java:203)
at android.database.sqlite.SQLiteOpenHelper.getWritableDatabase(SQLiteOpenHelper.java:118)
请帮忙。