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

后端 未结 16 2206
一整个雨季
一整个雨季 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:42

    In my case I changed my db name and its work for me

    0 讨论(0)
  • 2020-12-15 05:46

    try remove getReadableDatabase

     if (!dbExist) {
                synchronized (this) {
    
                    db_Read = this.getReadableDatabase();
                    Log.e("Path 2", this.getReadableDatabase().getPath());
                    db_Read.close();
    
                    copyDataBase();
                    Log.v("copyDataBase---", "Successfully");
                }
    

    to

     if (!dbExist) {
                synchronized (this) {
    
                    //db_Read = this.getReadableDatabase();
                  //  Log.e("Path 2", this.getReadableDatabase().getPath());
                  //  db_Read.close();
    
                    copyDataBase();
                    Log.v("copyDataBase---", "Successfully");
                }
    
    0 讨论(0)
  • 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);
    
    }
    
    0 讨论(0)
  • 2020-12-15 05:47

    it is another solution to this problem some time developer didnot knows that there is not space between column name and its end like KEY_ADDRESS, this is wrong approach use space between comma and name of attribute

    0 讨论(0)
提交回复
热议问题