Android: failed to set Locale () when building, closing database

I am trying to create a database with 12 different tables, which works to this day. Now every time I launch my application for the first time after uninstalling it and reinstalling it (or just cleaning up the application data), I get the error message indicated in the header. However, the second time I run the application after receiving this error, it works fine. Below is the code from my DatabaseHelper class, which is more or less the same as the android notepad tutorial.

This error occurs after the database was opened in my activity, and I try to make my first request.

Any suggestions on what might 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; } } 
+6
source share
1 answer

The problem is that your database probably does not include metadata related to Android.

You need to use the SQLiteDatabase.NO_LOCALIZED_COLLATORS flag when calling SQLiteDatabase.openDatabase() - this no longer causes a problem. At least it worked for me.

+6
source

Source: https://habr.com/ru/post/898579/


All Articles