1

i am developing an application which uses sqlite db for storing records. I am developing this application on SDK 1.5.. when i test the application on 1.5 device it works good but when i try to run it on a 1.6 device i get a force close message with following logcat output:

03-19 09:31:35.206: ERROR/AndroidRuntime(224): Uncaught handler: thread main exiting due to uncaught exception

03-19 09:31:35.226: ERROR/AndroidRuntime(224): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.abc.android/com.abc.android.app}: android.database.sqlite.SQLiteException: unable to open database file

03-19 09:31:35.226: ERROR/AndroidRuntime(224): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2454)

03-19 09:31:35.226: ERROR/AndroidRuntime(224): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2470)

03-19 09:31:35.226: ERROR/AndroidRuntime(224): at android.app.ActivityThread.access$2200(ActivityThread.java:119)

03-19 09:31:35.226: ERROR/AndroidRuntime(224): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1821)

03-19 09:31:35.226: ERROR/AndroidRuntime(224): at android.os.Handler.dispatchMessage(Handler.java:99)

03-19 09:31:35.226: ERROR/AndroidRuntime(224): at android.os.Looper.loop(Looper.java:123)

03-19 09:31:35.226: ERROR/AndroidRuntime(224): at android.app.ActivityThread.main(ActivityThread.java:4310)

03-19 09:31:35.226: ERROR/AndroidRuntime(224): at java.lang.reflect.Method.invokeNative(Native Method)

03-19 09:31:35.226: ERROR/AndroidRuntime(224): at java.lang.reflect.Method.invoke(Method.java:521) 03-19 09:31:35.226: ERROR/AndroidRuntime(224): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:860)

03-19 09:31:35.226: ERROR/AndroidRuntime(224): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618)

03-19 09:31:35.226: ERROR/AndroidRuntime(224): at dalvik.system.NativeStart.main(Native Method)

03-19 09:31:35.226: ERROR/AndroidRuntime(224): Caused by: android.database.sqlite.SQLiteException: unable to open database file

03-19 09:31:35.226: ERROR/AndroidRuntime(224): at android.database.sqlite.SQLiteDatabase.dbopen(Native Method)

03-19 09:31:35.226: ERROR/AndroidRuntime(224): at android.database.sqlite.SQLiteDatabase.(SQLiteDatabase.java:1697)

03-19 09:31:35.226: ERROR/AndroidRuntime(224): at android.database.sqlite.SQLiteDatabase.openDatabase(SQLiteDatabase.java:738)

03-19 09:31:35.226: ERROR/AndroidRuntime(224): at android.database.sqlite.SQLiteDatabase.openOrCreateDatabase(SQLiteDatabase.java:760)

03-19 09:31:35.226: ERROR/AndroidRuntime(224): at android.database.sqlite.SQLiteDatabase.openOrCreateDatabase(SQLiteDatabase.java:753)

03-19 09:31:35.226: ERROR/AndroidRuntime(224): at android.app.ApplicationContext.openOrCreateDatabase(ApplicationContext.java:473)

03-19 09:31:35.226: ERROR/AndroidRuntime(224): at android.content.ContextWrapper.openOrCreateDatabase(ContextWrapper.java:193)

03-19 09:31:35.226: ERROR/AndroidRuntime(224): at android.database.sqlite.SQLiteOpenHelper.getWritableDatabase(SQLiteOpenHelper.java:98)

03-19 09:31:35.226: ERROR/AndroidRuntime(224): at com.abc.android.DbAdapter.open(DbAdapter.java:101)

03-19 09:31:35.226: ERROR/AndroidRuntime(224): at com.abc.android.class1.onCreate(class1.java:105)

03-19 09:31:35.226: ERROR/AndroidRuntime(224): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)

03-19 09:31:35.226: ERROR/AndroidRuntime(224): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2417)

03-19 09:31:35.226: ERROR/AndroidRuntime(224): ... 11 more

DBAdapter.java

public DbAdapter open() throws SQLException {

        Log.d("DbAdapter", "in DbAdapter open()");

        mDbHelper = new DatabaseHelper(mCtx);
        mDb = mDbHelper.getWritableDatabase();        // line 101
        return this;
    }

 DatabaseHelper(Context context) {
 super(context, DATABASE_NAME, null, DATABASE_VERSION); 
 }

 @Override
 public void onCreate(SQLiteDatabase db) {
    db.execSQL(DATABASE_QUERY);
 }              

class1.java

mDB = new DbAdapter(Class1.this);
mDB.open();             // line 105

Please help..what do i do????

3
  • Out of curiosity are you closing the connection after? Commented Mar 19, 2010 at 4:43
  • Why inside of your DBAdapter.java class do you have a floating DatabaseHelper constructor? Commented Mar 19, 2010 at 4:46
  • Are you sure the database is created and present when in runs line 101 in DBAdapter? This android.database.sqlite.SQLiteException: unable to open database file may mean that it's not created yet.. Commented Apr 14, 2011 at 15:47

1 Answer 1

1

Make sure DATABASE_NAME contains a value that is just a file name and nothing more, no slashes, etc.

Like this: final String DATABASE_NAME = "mydata.db";

And if that looks good, uninstall your app from the phone applications menu and re-install it.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.