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!
Asked
Active
Viewed 9,551 times
3

halilkaya
- 467
- 6
- 21
-
Are you calling `getReadableDatabase()` or `getWritableDatabase()`? Please post the code you use to create and open your database. – Sam Jan 11 '13 at 21:49
-
It may be corrupt data stored in the memory. Try going to your application in device settings and manage applications then clear data. – codeMagic Jan 11 '13 at 21:50
-
Yes, I'm calling it to many places. I put it into the try...catch structure, and it gives this error. – halilkaya Jan 11 '13 at 21:50
-
@codeMagic I also did it. I cleared all data, I moved the application from sd card to internal storage. But, no positive result!.. – halilkaya Jan 11 '13 at 21:52
-
According to documentation SQLiteOpenHelper version should start from 1. So updating from 0 to 1 isn't necessarily supported. – harism Jan 11 '13 at 21:55
-
The version that I've written is 1. I don't know why it's trying to upgrade it from 0 to 1. – halilkaya Jan 11 '13 at 21:56
-
@harism This is true, but SQLiteDatabase starts every new database at version 0. I believe SQLiteOpenHelper uses version 0 to call `onCreate()` when the database is first created and not every time a version 1 database is opened. – Sam Jan 11 '13 at 22:03
3 Answers
5
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);
}

Ramesh Sangili
- 1,633
- 3
- 17
- 31
-
I have one table. I dropped it if exists... But it didn't work again. – halilkaya Jan 11 '13 at 21:53
-
Hope you are not using dbdelete, Please try again...http://stackoverflow.com/questions/7313029/sqliteexception-cant-upgrade-read-only-database-from-version-1-to-2 – Ramesh Sangili Jan 11 '13 at 22:09
-
I looked at this topic. I already didn't use db.delete. In this topic, the solution is drop table if exists... I also tried it but unfortunately it didn't work again :( – halilkaya Jan 11 '13 at 22:37
-
-
I don't think so. Because I changed database name and I uninstalled my app and reinstalled it. – halilkaya Jan 11 '13 at 22:46
-
Sorry, I am also running out of ideas. I have a strong feeling there might be some typo wiht the table names – Ramesh Sangili Jan 11 '13 at 23:16
-
Thanks for your all answers. I'm really sorry to make you busy. In my SQL sentence that creates table, I've written ' id INTEGER PRIMARY ' (not with KEY) wrongly. So, it returns error. I wrote it and it was fixed. I'm really sorry about that again. Thank you... – halilkaya Jan 11 '13 at 23:36
-
How is this an acceptable solution? It will delete all the data every time the database is upgraded. – jack Aug 04 '20 at 18:30
0
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.

alphonzo79
- 938
- 11
- 12
0
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.