Problem with sqlite database on android platform
- by mudit
hi all
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????