开发者

Database not copied in Android 2.3.3

I write the code of database copy in /data/data path. but it gives this error

sqlite3_open_v2("/data/data/com.开发者_Go百科mycom.package/databases/My Bookback", &handle, 2, NULL) failed 

Caused by: android.database.sqlite.SQLiteException: unable to open  database file and copy.  05-23 13:19:46.746: ERROR/AndroidRuntime(9120): 
Caused by: android.database.sqlite.SQLiteException: no such table: Details: ,


The problem is that the dest directory could not be present on filesystem.

I resolved in this way.

File fDir = new File(DB_PATH);
if (!fDir.exists()) {
    Log.d(TAG, "Create directory " + fDir.getAbsolutePath() + " - " + fDir.mkdir());
}


Copying the database from assets is generally a bad idea. DB should be created/accessed through the SQLiteOpenHelper class. You can use the onCreate method to populate the DB content.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜