I'm trying to create a database with 12 different tables which has been working fine until today. Now every time I start my app for the first time after uninstalling it and re-installing it (or just clear app data) I get the error message seen in the title. However, the second time I start the app after getting this error it works fine. The code bellow is from my DatabaseHelper class which is more or less the same as the android notepad tutorial.
This error comes after the database has been opened in my activity and I try to make my first query.
Any suggestions of what could cause this and how to solve it?
private static class DatabaseHelper extends SQLiteOpenHelper {
private static String DB_PATH = "/data/data/my_app/databases/";
DatabaseHelper(Context context) {
super(context, DATABASE_NAME, null, DATABASE_VERSION);
}
@Override
public void onCreate(SQLiteDatabase db) {
if (!checkDataBase()) {
db.execSQL(TABLE_1);
db.execSQL(TABLE_2);
db.execSQL(TABLE_3);
db.execSQL(TABLE_4);
db.execSQL(TABLE_5);
db.execSQL(TABLE_6);
db.execSQL(TABLE_7);
db.execSQL(TABLE_8);
db.execSQL(TABLE_9);
db.execSQL(TABLE_10);
db.execSQL(TABLE_11);
db.execSQL(TABLE_12);
}
}
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
Log.w(TAG, "Upgrading database from version " + oldVersion + " to " + newVersion + ", which will destroy all old data");
db.execSQL("DROP TABLE IF EXISTS " + TABLE_1);
db.execSQL("DROP TABLE IF EXISTS " + TABLE_2);
db.execSQL("DROP TABLE IF EXISTS " + TABLE_3);
db.execSQL("DROP TABLE IF EXISTS " + TABLE_4);
db.execSQL("DROP TABLE IF EXISTS " + TABLE_5);
db.execSQL("DROP TABLE IF EXISTS " + TABLE_6);
db.execSQL("DROP TABLE IF EXISTS " + TABLE_7);
db.execSQL("DROP TABLE IF EXISTS " + TABLE_8);
db.execSQL("DROP TABLE IF EXISTS " + TABLE_9);
db.execSQL("DROP TABLE IF EXISTS " + TABLE_10);
db.execSQL("DROP TABLE IF EXISTS " + TABLE_11);
db.execSQL("DROP TABLE IF EXISTS " + TABLE_12);
onCreate(db);
}
private boolean checkDataBase() {
SQLiteDatabase checkDB = null;
try {
checkDB = SQLiteDatabase.openDatabase(DB_PATH + DATABASE_NAME, null, SQLiteDatabase.OPEN_READONLY);
checkDB.close();
} catch (SQLiteException e) {
}
return checkDB != null ? true : false;
}
}
The problem is that your database probably doesn't include Android-related metadata.
You need to use the SQLiteDatabase.NO_LOCALIZED_COLLATORS
flag when calling SQLiteDatabase.openDatabase()
- this no longer causes the problem. At least it worked for me.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With