开发者

Android app can't load database when database is copied over right after installing app

For testing purposes, I want to install my app and then copy over the db but I'm getting an error opening up the db:

06-09 20:20:54.414: INFO/Database(8854): sqlite returned: error code = 14, msg = cannot open file at source line 25467
06-09 20:20:54.414: ERROR/Database(8854): sqlite3_open_v2("/data/data/com.mydomain.myproductname/databases/myproductname.db", &handle, 6, NULL) failed

Even if I delete the db at this point and try to start the app it still doesn't work. The only way to make the error go away is to reinstall the app. Any suggestions for what I should check?

开发者_C百科

(This is a similar question to Android SQLiteOpenHelper cannot open database file but the solution the asker gave was to uninstall app but I don't want to do that. My provider is pretty similar to the notepad example except I also do some INSERTs after creating the tables though this doesn't seem to be the issue.)


How are you copying the database over? Is the database part of your assets? I would solve it by having an sql file in your assets. The sql file would contain all of the sql commands needed to generate the database. Then use an AssetManager to open an input stream from the sql file and declare an InputStreamReader on the InputStream and a BufferedReader on the InputStreamReader like this:

BufferedReader reader = new BufferedReader(new InputStreamReader(manager.open("filename", AssetManager.ACCESS_BUFFER)))

From there use the BufferedReader to get the SQL commands and run them on your database

db.rawQuery(reader.readLine(), null);
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜