Sunday, November 2, 2014

Android : Android SQLiteAssetHelper Can't upgrade read-only database from version 1 to 2:



I want to create an offline dictionary app, that need sometimes to get update and old database will be replaced by new one. It's what I want to do, and I did something like this with SQLiteAssetHelper Library:


Note: SQLiteAssetHelper will copy database from assets folder into app data folder



public class MyDb extends SQLiteAssetHelper {
private static final String DATABASE_NAME = "db.sqlite";
private static final int DATABASE_VERSION = 1;
public MyDb(Context context) {
super(context, DATABASE_NAME, null, DATABASE_VERSION);
}
}


now i want to update database, after puting new db.sqlite file into assets folder, I have manipulate my codes like this:



public class MyDb extends SQLiteAssetHelper {
private static final String DATABASE_NAME = "db.sqlite";
private static final int DATABASE_VERSION = 2;
public MyDb(Context context) {
super(context, DATABASE_NAME, null, DATABASE_VERSION);
}
}


but when i compiled and run, it says: Can't upgrade read-only database from version 1 to 2


what is the solution?


by clearing app data, it will works fine...


SORRY FOR MY BAD ENGLISH...


No comments:

Post a Comment