Random exception android.database.sqlite.SQLiteException: unable to open database file

后端 未结 7 578
孤街浪徒
孤街浪徒 2020-12-14 07:59

My app uses a uncaught exception handler that sends the stack trace to me when the app crashes. Often I get this report from random users.

I cannot replicate it, th

7条回答
  •  独厮守ぢ
    2020-12-14 08:35

    there can be if your app opens database from multiple threads at same time that can be the reason for this exception.

    please try synchronized method to open database.synchronized method will not allow database to be open from multiple threads at same time. put below code in your dbHelper

    private synchronized SQLiteDatabase getWritableDB() {
            //get your database and return it from this method.
    }
    

    and call these method when your are getting db. Hope it will help.

提交回复
热议问题