Your question is not that clear, but I'll try to answer.
Most likely, your database either:
- Don't exist yet, and you have to create it;
- Your database file is read only, you have to change it (This question might be related).
For #2, instead of using SQLiteOpenHelper#getReadableDatabase()
, use SQLiteOpenHelper#getWritableDatabase
If your database is on an external storage unit, you have a few other things to check:
- Is the external storage currently mounted? If not, you can't access the db.
- Is it mounted as read only? If so, you'll have to change this.
- Have you checked the path? Is it correct?
The problem might be on any of those topics.
To check if it's mounted as read-only, try the following:
/* Checks if external storage is available for read and write */
public boolean isExternalStorageWritable() {
String state = Environment.getExternalStorageState();
if (Environment.MEDIA_MOUNTED.equals(state)) {
return true;
}
return false;
}
/* Checks if external storage is available to at least read */
public boolean isExternalStorageReadable() {
String state = Environment.getExternalStorageState();
if (Environment.MEDIA_MOUNTED.equals(state) ||
Environment.MEDIA_MOUNTED_READ_ONLY.equals(state)) {
return true;
}
return false;
}
Taken from here.
For more info on the Environment
class, please refer to the docs.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…