Android - How to Use SQLiteDatabase.open?

Posted by Edwin Lee on Stack Overflow See other posts from Stack Overflow or by Edwin Lee
Published on 2010-04-18T01:56:53Z Indexed on 2010/04/18 2:03 UTC
Read the original article Hit count: 527

Filed under:

Hi all,

i'm trying to use

SQLiteDatabase.openDatabase(
    "/data/data/edwin11.myapp/databases/myapp.db", null, (SQLiteDatabase.CREATE_IF_NECESSARY | SQLiteDatabase.NO_LOCALIZED_COLLATORS));

to create/open a database instead of making use of the SQLiteOpenHelper (because i want to pass in the flag SQLiteDatabase.NO_LOCALIZED_COLLATORS.

However, i am getting this exception for that line of code:

04-18 09:50:03.585: ERROR/Database(3471): sqlite3_open_v2("/data/data/edwin11.myapp/databases/myapp.db", &handle, 6, NULL) failed
04-18 09:50:03.665: ERROR/AndroidRuntime(3471): java.lang.RuntimeException: An error occured while executing doInBackground()
04-18 09:50:03.665: ERROR/AndroidRuntime(3471):     at android.os.AsyncTask$3.done(AsyncTask.java:200)
04-18 09:50:03.665: ERROR/AndroidRuntime(3471):     at java.util.concurrent.FutureTask$Sync.innerSetException(FutureTask.java:234)
04-18 09:50:03.665: ERROR/AndroidRuntime(3471):     at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:258)
04-18 09:50:03.665: ERROR/AndroidRuntime(3471):     at java.util.concurrent.FutureTask.run(FutureTask.java:122)
04-18 09:50:03.665: ERROR/AndroidRuntime(3471):     at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:648)
04-18 09:50:03.665: ERROR/AndroidRuntime(3471):     at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:673)
04-18 09:50:03.665: ERROR/AndroidRuntime(3471):     at java.lang.Thread.run(Thread.java:1060)
04-18 09:50:03.665: ERROR/AndroidRuntime(3471): Caused by: android.database.sqlite.SQLiteException: unable to open database file
04-18 09:50:03.665: ERROR/AndroidRuntime(3471):     at android.database.sqlite.SQLiteDatabase.dbopen(Native Method)
04-18 09:50:03.665: ERROR/AndroidRuntime(3471):     at android.database.sqlite.SQLiteDatabase.<init>(SQLiteDatabase.java:1584)
04-18 09:50:03.665: ERROR/AndroidRuntime(3471):     at android.database.sqlite.SQLiteDatabase.openDatabase(SQLiteDatabase.java:638)
...

Doing some testing just before that line of code (using File.isExists) shows that the file /data/data/edwin11.myapp/databases/myapp.db does not exist.

Would that be the cause of the error? (Or am i just using SQLiteDatabase.openDatabase the wrong way?)

Would it help if i create the file beforehand? (Shouldn't that be taken care of by the SQLiteDatabase.CREATE_IF_NECESSARY flag that i passed in?)

If creating the file manually is the way to go, is it just an empty file, or do i have to write something to it?

Thanks and Regards.

© Stack Overflow or respective owner

Related posts about android