views:

151

answers:

1

When I add this code to my Android 2.1 Java app, it fails:

db=SQLiteDatabase.openOrCreateDatabase("Locations", null);

Do I need a special permission to create a database, or can anybody provide a suggestion how to find out what goes wrong?

Here is the LogCat output:

04-04 15:04:28.702: DEBUG/ddm-heap(703): Got feature list request
04-04 15:04:29.642: ERROR/Database(703): sqlite3_open_v2("Locations", &handle, 6, NULL) failed
04-04 15:04:29.652: DEBUG/AndroidRuntime(703): Shutting down VM
04-04 15:04:29.662: WARN/dalvikvm(703): threadid=3: thread exiting with uncaught exception (group=0x4001b188)
04-04 15:04:29.662: ERROR/AndroidRuntime(703): Uncaught handler: thread main exiting due to uncaught exception
04-04 15:04:29.702: ERROR/AndroidRuntime(703): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.gormtech.zyx.RejseplanQuick/com.xxx.zyx.xxx.HelloAndroid}: android.database.sqlite.SQLiteException: unable to open database file
+2  A: 

Any app can make a SQLiteDatabase without any special permissions.

I'm a little thrown by your code snippet because in my documents/SDK openOrCreateDatabase (on Context) takes three parameters: name, operating mode and factory. http://developer.android.com/intl/fr/reference/android/content/Context.html

It will be very revealing to see the output of your 'adb logcat'. Either run the adb application from a console, or bring up the LogCat window in Eclipse (it might help to switch to the DDMS Perspective). Run the app, get the failure and paste the later lines here.

Jim Blackler
I am not using the Context class, but the SQLiteDatabase class, where it only takes 2 parameters.
Lars D
Jim Blackler
It seems to be documented here as a bug: http://code.google.com/p/android/issues/detail?id=949
Lars D
This solved it: db=this.openOrCreateDatabase("Locations.db", MODE_PRIVATE, null); - thanks
Lars D
Glad you got it working.
Jim Blackler