开发者

Android sqlite exception,how to fix?

开发者 https://www.devze.com 2023-01-10 06:06 出处:网络
SQLiteDatabase database = SQLiteDatabase.openDatabase(\"/data/data/com.android.browser/databases/browser.db\",
SQLiteDatabase database = SQLiteDatabase.openDatabase("/data/data/com.android.browser/databases/browser.db",
null, 0);
database.setLockingEnabled(true);

database.delete("bookmarks", "_id=2", null);
database.close();

error

08-06 05:53:45.769: ERROR/tt(958): android.database.sqlite.SQLiteException: error code 14: unable to open database file
08-06 05:53:45.769: ERROR/tt(958):     at android.database.sqlite.SQLiteStatement.native_execute(Native Method)
08-06 05:53:45.769: ERROR/tt(958):     at android.database.sqlite.SQLiteStatement.execute(SQLiteStatement.java:66)
08-06 05:53:45.769: ERROR/tt(958开发者_StackOverflow中文版):     at android.database.sqlite.SQLiteDatabase.delete(SQLiteDatabase.java:1362)
08-06 05:53:45.769: ERROR/tt(958):     at com.iwidsets.sqlite.manager.SQLiteManager.onCreate(SQLiteManager.java:48)
08-06 05:53:45.769: ERROR/tt(958):     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1123)
08-06 05:53:45.769: ERROR/tt(958):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2231)
08-06 05:53:45.769: ERROR/tt(958):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2284)
08-06 05:53:45.769: ERROR/tt(958):     at android.app.ActivityThread.access$1800(ActivityThread.java:112)
08-06 05:53:45.769: ERROR/tt(958):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1692)
08-06 05:53:45.769: ERROR/tt(958):     at android.os.Handler.dispatchMessage(Handler.java:99)
08-06 05:53:45.769: ERROR/tt(958):     at android.os.Looper.loop(Looper.java:123)
08-06 05:53:45.769: ERROR/tt(958):     at android.app.ActivityThread.main(ActivityThread.java:3948)
08-06 05:53:45.769: ERROR/tt(958):     at java.lang.reflect.Method.invokeNative(Native Method)
08-06 05:53:45.769: ERROR/tt(958):     at java.lang.reflect.Method.invoke(Method.java:521)
08-06 05:53:45.769: ERROR/tt(958):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:782)
08-06 05:53:45.769: ERROR/tt(958):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:540)
08-06 05:53:45.769: ERROR/tt(958):     at dalvik.system.NativeStart.main(Native Method)


from the locat result this seems to be where the problem is:

SQLiteDatabase database = SQLiteDatabase.openDatabase("/data/data/com.android.browser/databases/browser.db", null, 0);

so this gets me thinking about file permissions, as right off when I started trying to debug stuff on my actual phone i noticed the /data folder wasn't accessible in the file browser turns out if the phone isn't rooted that's normal. lets take this a step further, I think it's possible that programs also do not a have access to anything in the /data folder except for the one directory that is for it's own stuff. so if your package is not named "com.android.browser" well it'll likely not be able to read that folder and thus trying to open files in it would fail. also not completely sure if this applies here but I've also run into cases where it fails when you use the absolute path but works when you use the relative path to the same location. so to that end I'd say using

SQLiteDatabase database = SQLiteDatabase.openDatabase("browser.db", null, 0);

so if your package is named com.android.browser my suggestion should plunk it in the same spot. if it's not then it's quite likely it doesn't have permission to that other app's files. I think it's possible to get the permission but you gotta do something to both program to enable them to share files. I did read somewhere that android does normally run each app in a separate space and it says it goes so far as using separate Linux accounts for each, being that is what android os is built on to.

so if your trying to edit the bookmarks in the built in browser i don't think you can modify it's database directly, being as you can't modify that program to tell it to share it's files with your program; but you may be able to send intents to the app and have it carry them out that way.

0

精彩评论

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