Hello everyone, this is the question that has tormented me for several days:

CREATE TABLE android_metadata failed

Failed to setLocale () when constructing, closing the database

net.sqlcipher.database.SQLiteException: file: create locale table failed

Here is the code to work with Sqlcipher:

public class DBHelper extends SQLiteOpenHelper implements DataStore { private static DBHelper sInstance; private String DBKey; public DBHelper(Context context) { super(context, DBConst.DB_NAME, null, DBConst.DB_VERSION); } public static synchronized DBHelper getInstance() { if (sInstance == null) { SQLiteDatabase.loadLibs(App.getContext()); sInstance = new DBHelper(App.getContext()); } return sInstance; } public void onCreate(SQLiteDatabase db) { db.execSQL(createTable(DBConst.TABLE_NAME)); } public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) { db.execSQL(dropTable(DBConst.TABLE_NAME)); onCreate(db); } private String createTable(String name) { return "CREATE TABLE IF NOT EXISTS " + name + " (" + DBConst.DB_ID + " integer primary key," + DBConst.DB_DATA + " text);"; } private String dropTable(String name) { return "DROP TABLE IF EXISTS " + name; } public synchronized void deleteTable(String name) { SQLiteDatabase db = this.getWritableDatabase(getDBKey()); db.delete(name, null, null); db.close(); } private String getDBKey() { if (DBKey == null) DBKey = PreferencesStorage.getInstance().getDBKey(); return DBKey; } @Override public synchronized void writeData(NoSqlEntity entity, String tableName) { SQLiteDatabase db = this.getWritableDatabase(getDBKey()); ContentValues cv = new ContentValues(); cv.put(DBConst.DB_ID, entity.entityId); cv.put(DBConst.DB_DATA, entity.entityData); db.insert(tableName, null, cv); db.close(); } @Override public synchronized <T> List<T> readAllData(Class<T> clazz, String tableName) { ArrayList<T> list = new ArrayList<>(); SQLiteDatabase db = this.getWritableDatabase(getDBKey()); Cursor c = db.query(tableName, new String[]{ DBConst.DB_ID, DBConst.DB_DATA }, null, null, null, null, null); if (c.moveToFirst()) { do { list.add(new GsonSerialization().deserializeFromDB(c.getString(c.getColumnIndex(DBConst.DB_DATA)), clazz)); } while (c.moveToNext()); } c.close(); db.close(); return list; } } 

If the key to the database is hardcoded by a constant, then there is no problem.

From the PreferencesStorage key is correct.

What am I doing wrong?

  • I assume that the error appears in the version of Android M. - Vlad Shipugin

1 answer 1

Look in debug mode the length of the key and the return value from PreferenceStorage is the same?

There is such an issue when working with SharedPreferences - https://code.google.com/p/android/issues/detail?id=159799