Reputation: 467
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!
Upvotes: 3
Views: 9769
Reputation: 1
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.
Upvotes: 0
Reputation: 928
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.
Upvotes: 0
Reputation: 1633
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);
}
Upvotes: 5