Failed to open database/ Failed to change locale for (database) to 'en_US'

前端 未结 4 933
误落风尘
误落风尘 2021-01-20 03:36

I have read solution from Failed to change locale for db '/data/data/my.easymedi.controller/databases/EasyMediInfo.db' to 'en_US' but it doesnt help me. I st

4条回答
  •  猫巷女王i
    2021-01-20 03:38

    I couldn't put all these codes in the comments, so please try these: Keep in mind that I am not adding all the boilerplates... ok?

    Change checkDb method:

    private boolean checkDataBase(){
         File dbFile = new File( DATABASE_PATH, DATABASE_NAME );
         return dbFile.exists();
    }
    

    Change createDb method:

    public void createDataBase() {
        if(checkDb()){
            //do nothing
        } else {
            copyDatabase();
        }
    }
    

    Change copyDatabase() method:

    private void copyDataBase(){
          getReadableDatabase();
    
          //add the rest of your current implementation
    
    }
    

    Change accessibility of your constructor to private and add these methods:

    private DBHelper mInstance = null;
    public static DBHelper getInstance(Context context) {
       if(mInstance == null)
            mInstance = new DBHelper(context)
       return mInstance;
    }
    //remove the old openDatabase method
    public SQLiteDatabase openDatabase() {
       return getReadableDatabase(); //or you can use getWritableDatabase();
    }
    

    Besides I noticed that your db version in the posted code is 18 while in the logs that you posted it's saying 5 or 6? Can you post the latest logs...

提交回复
热议问题