SQLite Android cannot open database file

后端 未结 5 1265
夕颜
夕颜 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:20

    Although not relevant for your current issue, the onUpgrade method in SQLiteOpenHelper is also bound to fail in the future: If the action you want to take when a new version of the db is deployed, is to start from scratch, you will need to delete the old tables first.

    Edit After some research I found out that your problem is rather common:

    Android SQLiteOpenHelper cannot open database file

    the 3 links provided with this answer

    https://stackoverflow.com/a/8957994/2177061

    are particularly interesting and provide some kind of workaround, should you not find a clean way to make the bug disappear.

    That said if I where in you, as a first attempt to solve your problem before delving with complex workarounds, I would try to update all Android Development Tools (the SDK in particular, but updating the eclipse plugin won't hurt), completely remove your app from both the emulator and devices, and run it again.

    Good luck!

    Edit 2 Disregard the following remark (it's not correct, I leave it here for reference)

    Your code doesn't work because the SQL query is wrong: you spelled

    integet promary
    

    where it should have been

    integer primary
    

    (besides, it happens to me too that I get crazy with the Android db classes only to find that the problem resides in the SQL queries :) )

    Hope this helps

提交回复
热议问题