SQLite Android cannot open database file

后端 未结 5 1234
夕颜
夕颜 2021-01-18 13:34

Edit: I tried this on my phone and it works, can anyone tell me why it does not work on an emulator?

I am trying to open a database on android, but it is throwing an

5条回答
  •  暖寄归人
    2021-01-18 14:11

    I was looking for a solution to this problem and I didn't find anything that worked... but fortunately I did something that solved it. This is what I did:

    Open your adb shell and remove the database you are trying to open. For those who don't know how to use the Linux terminal:

    // first open adb shell from a command line

    adb shell
    

    // then these are the commands you need (change YOUR.APP.PACKAGE for your app package, it should look like com.domain.apilcation )

    cd /data/data/YOUR.APP.PACKAGE/databases/
    ls
    

    The last command (ls) will list all the databases that you created for your project and now you can remove the database that you can't open. First, you should copy it, so you don't lose any important data. (I will suppose that your database is called your_database.db)

    cp your_database.db your_database.db_backup
    rm your_database.db
    

    Then you should launch your app, it should create a new database and for me this solved the problem permanently.

    I hope this helps!

提交回复
热议问题