Android: unable to open database file [duplicate]
When I tried to open a sqlite database, it caught exception :
android.database.s开发者_运维技巧qlite.SQLiteException : unable to open databse file.
My code is :
final String DATABASENAME = "MY_DB";
SQLiteDatabase objDb = this.openOrCreateDatabase(DATABASENAME, MODE_PRIVATE, null);
Edited
This is working fine android 2.2. But it caught exception in android 2.1.
Please help me... Thank you..
File sdcardfile = Environment.getExternalStorageDirectory();
db = SQLiteDatabase.openOrCreateDatabase(sdcardfile.getPath()
+ "/BadBrain/question.db", null);
Make sure the "BadBrain" directory exists, or you can create it!
Please also check permission(android.permission.WRITE_EXTERNAL_STORAGE) on manifest.xml.
I got the same error while running my app on JB devices. I was because they altered database path /data/data/{package_name}/databases/
. To resolve use Android inbuilt API method as follows rather than hard coded path
mContext.getDatabasePath(DATABASE_NAME).getPath();
Try and see like this.
SQLiteDataBase objDb = SQLiteDatabase.openDatabase(DATABASENAME, null, SQLiteDatabase.OPEN_READWRITE);
do you have the table android_meta data and locale set in your table?
Look at first steps here: http://www.reigndesign.com/blog/using-your-own-sqlite-database-in-android-applications/
精彩评论