android: Can't upgrade read-only database from version 0 to 1

喜你入骨 提交于 2019-12-10 21:24:23

问题



I know there are many topic that have the same title, but I've tried all of them. I couldn't solve my problem.
The error I get is exactly this:

android.database.sqlite.SQLiteException: Can't upgrade read-only database from version 0 to 1: /data/data/com.halilkaya.flashcard/databases/flashcarddb.db

Actually, it works on the emulator, but when I install it on my phone, it doesn't work!


回答1:


Hope you are dropping the table and upgrading it aagain as below

public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
    db.execSQL("DROP TABLE IF EXISTS " + LOCATION_TABLE);
    db.execSQL("DROP TABLE IF EXISTS " + PHONE_TABLE);
    // Create tables again
    onCreate(db);

}



回答2:


When I hit this there was another sql exception earlier in the logcat (my HTC OneX test phone likes to hide crashes and make me go looking for them instead of just crashing). I had a malformed statement in my upgrade logic. Once I cleared that up I no longer got the "can't upgrade read-only database" error.




回答3:


this is a class that is started from an onclick button using an intent.

public class disp_emails_sent extends Activity

......
protected void onCreate(Bundle bd) 
    {
        super.onCreate(bd);
        setContentView(R.layout.disp_db_res);

        lv = (ListView) findViewById(R.id.myEmail_list);

        List<String> arrayL = new ArrayList<String>();
        db_handler dbHand = new db_handler(disp_emails_sent.this);

(disp_emails_sent.this) shown above is usually where you would pass your context. this.getApplicationContext() didnt work for me but this did.

Not sure how it worked but it did.

Did try the above answers provided by the community but this wasnt the issue.

Would like an explanation if anyone has it.



来源:https://stackoverflow.com/questions/14287191/android-cant-upgrade-read-only-database-from-version-0-to-1

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