开发者

Android: unable to open database file [duplicate]

This question already has answers here: SQLite Android . unable to open database file (2 answers) Closed 9 years ago.

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/

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜