Caused by: android.database.sqlite.SQLiteException: no such table: (code 1) Android

后端 未结 16 2344
一整个雨季
一整个雨季 2020-12-15 05:01

We have a sqlite database in our Application. Its working fine for all the users but few of them experiencing the Caused by: android.database.sqlite.SQLiteException: n

16条回答
  •  独厮守ぢ
    2020-12-15 05:47

    The problem is because some of device is upgrading your app, so the checkDataBase() returning true, so you are not calling copyDataBase(). So you are using previous database which doesn't have generalSettings table. To solve this try:

    @Override
    public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
    if(newVersion>oldVersion)
      copyDatabase();
    }
    

    and also update your constructor:

    public InstallDB(Context context, String name) {
        super(context, name, null, DB_VERSION); 
        // DB_VERSION is an int,update it every new build
    
        this.ctx = context;
        this.DBNAME = name;
        this.DBPATH = this.ctx.getDatabasePath(DBNAME).getAbsolutePath();
        Log.e("Path 1", DBPATH);
    
    }
    

提交回复
热议问题