3

When I tried to open a sqlite database, it caught exception :

android.database.sqlite.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..

1
  • show your DATABASENAME value Commented Mar 15, 2012 at 19:33

5 Answers 5

2
File sdcardfile = Environment.getExternalStorageDirectory();

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

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

Sign up to request clarification or add additional context in comments.

Comments

1

Please also check permission(android.permission.WRITE_EXTERNAL_STORAGE) on manifest.xml.

Comments

1

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();

Comments

0

Try and see like this.

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

1 Comment

I am still getting the same error
0

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/

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.