Android: cannot open database file

When I tried to open the sqlite database, it detected an exception:

android.database.sqlite.SQLiteException: Unable to open database file.

My code is:

 final String  DATABASENAME   =    "MY_DB"; 
 SQLiteDatabase   objDb =  this.openOrCreateDatabase(DATABASENAME, MODE_PRIVATE, null);

Edited

This works great on Android 2.2. But this was an exception in android 2.1.

Please help me ... Thanks ..

+3
source share
5 answers
File sdcardfile = Environment.getExternalStorageDirectory();

db = SQLiteDatabase.openOrCreateDatabase(sdcardfile.getPath()
                                         + "/BadBrain/question.db", null);

Make sure the BadBrain directory exists, or you can create one!

+2
source

Also check the permission (android.permission.WRITE_EXTERNAL_STORAGE) on manifest.xml.

+1
source

I have the same error when running my application on JB devices. I was because they changed the database path /data/data/{package_name}/databases/. To allow the use of the Android built-in API method, rather than a hard-coded path

mContext.getDatabasePath(DATABASE_NAME).getPath();
+1
source

Try it and look like this.

SQLiteDataBase objDb = SQLiteDatabase.openDatabase(DATABASENAME, null, SQLiteDatabase.OPEN_READWRITE);
0
source

Do you have an android_meta data table and locale set in your table?

Take a look at the first steps here: http://www.reigndesign.com/blog/using-your-own-sqlite-database-in-android-applications/

0
source

All Articles