App crashes upgrading sqlite database first time

前端 未结 1 1223
清歌不尽
清歌不尽 2021-01-13 07:10

my app experiences a crash when the sqlite database is updated the first time. Reloading the app, it works fine from then on. I\'m guessing this has to do with the onUpgrade

相关标签:
1条回答
  • 2021-01-13 07:58

    You don't need to delete the database, just copy over it using the method you've alady defined (copyDataBase), like this:

    @Override  
    public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {  
        Toast.makeText(myContext, "onUpgrade called!", Toast.LENGTH_LONG).show();  
        if (oldVersion < newVersion) {  
            Log.v("Database Upgrade", "Database version higher, upgrading");  
            try { 
                copyDataBase(); 
            } catch (IOException e) { 
                throw new Error("Error upgrading database"); 
            } 
        } 
    }  
    
    0 讨论(0)
提交回复
热议问题