Android Database Error - getWriteableDatabase

我的未来我决定 提交于 2020-01-24 15:39:06

问题


So I have an application on the market place. It's been running fine for several months. I've updated it twice with small bug fixes and made no change to the database what so ever.

Some of my users are getting the following error:

android.util.Log$TerribleFailure: Can t downgrade read-only database from version 2 to 1: /data/data/myapp/databases/MyAppDB
at android.util.Log.wtf(Log.java:275)
at android.util.Log.wtf(Log.java:254)
at android.database.sqlite.SQLiteOpenHelper.getWritableDatabase(SQLiteOpenHelper.java:129)

As I mentioned, there has been no change to the database if any of the updates. It obviously crashes when the getWriteableDatabase method is called. I'm stumped as to why this error is occurring.

My best guess is that the user's phone has no more space left and thus a writable database can't be openend and thus crashes the app.

Any ideas?


回答1:


A sqlite database has a version number. The version number is set when you open the database.

For example, if you use SQLiteOpenHelper, the constructor has int version parameter.

The error you get happened because on the user's device there is an old database with version=2 set, but on your program update you are trying to open that old database requesting version=1. That's not allowed.

Just set the version on the updated program to 2 or more.



来源:https://stackoverflow.com/questions/8223449/android-database-error-getwriteabledatabase

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!