1

I have written an Android application that uses SQLite database which is saved in assets folder. This database has 4 tables: "table1", "table2" and "table3" and "android_metadata" . The application works fine on most devices, but some crashes have been reported. So I used acra (Application Crash Report for Android, http://code.google.com/p/acra/ ) to collect the log. I am sure that the database has "table2" table, however the log says there is no such table. I really wonder why it works fine on some devices, but crashes on some others ? The model of phone is Samsung GT-I9001GT, Android 2.3.3 . Some HTC desire HD had this problem too. Please help me resolve it. Thanks.

(The database file size is 33KB)

Log

java.lang.RuntimeException: Unable to start activity ComponentInfo{english.idiom/english.idiom.Category2Activity}: android.database.sqlite.SQLiteException: no such table: table2: , while compiling: SELECT subject,table2_id FROM table2 WHERE table1_id=8
    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1651)
    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1667)
    at android.app.ActivityThread.access$1500(ActivityThread.java:117)
    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:935)
    at android.os.Handler.dispatchMessage(Handler.java:99)
    at android.os.Looper.loop(Looper.java:123)
    at android.app.ActivityThread.main(ActivityThread.java:3687)
    at java.lang.reflect.Method.invokeNative(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:507)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:867)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:625)
    at dalvik.system.NativeStart.main(Native Method)
Caused by: android.database.sqlite.SQLiteException: no such table: table2: , while compiling: SELECT subject,table2_id FROM table2 WHERE table1_id=8
    at android.database.sqlite.SQLiteCompiledSql.native_compile(Native Method)
    at android.database.sqlite.SQLiteCompiledSql.compile(SQLiteCompiledSql.java:92)
    at android.database.sqlite.SQLiteCompiledSql.<init>(SQLiteCompiledSql.java:65)
    at android.database.sqlite.SQLiteProgram.<init>(SQLiteProgram.java:83)
    at android.database.sqlite.SQLiteQuery.<init>(SQLiteQuery.java:49)
    at android.database.sqlite.SQLiteDirectCursorDriver.query(SQLiteDirectCursorDriver.java:42)
    at android.database.sqlite.SQLiteDatabase.rawQueryWithFactory(SQLiteDatabase.java:1356)
    at android.database.sqlite.SQLiteDatabase.rawQuery(SQLiteDatabase.java:1324)
    at english.idiom.Category2Activity.getContents(Category2Activity.java:176)
    at english.idiom.Category2Activity.Initialize(Category2Activity.java:138)
    at english.idiom.Category2Activity.onCreate(Category2Activity.java:70)
    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1615)
    ... 11 more
android.database.sqlite.SQLiteException: no such table: table2: , while compiling: SELECT subject,table2_id FROM table2 WHERE table1_id=8
    at android.database.sqlite.SQLiteCompiledSql.native_compile(Native Method)
    at android.database.sqlite.SQLiteCompiledSql.compile(SQLiteCompiledSql.java:92)
    at android.database.sqlite.SQLiteCompiledSql.<init>(SQLiteCompiledSql.java:65)
    at android.database.sqlite.SQLiteProgram.<init>(SQLiteProgram.java:83)
    at android.database.sqlite.SQLiteQuery.<init>(SQLiteQuery.java:49)
    at android.database.sqlite.SQLiteDirectCursorDriver.query(SQLiteDirectCursorDriver.java:42)
    at android.database.sqlite.SQLiteDatabase.rawQueryWithFactory(SQLiteDatabase.java:1356)
    at android.database.sqlite.SQLiteDatabase.rawQuery(SQLiteDatabase.java:1324)
    at english.idiom.Category2Activity.getContents(Category2Activity.java:176)
    at english.idiom.Category2Activity.Initialize(Category2Activity.java:138)
    at english.idiom.Category2Activity.onCreate(Category2Activity.java:70)
    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1615)
    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1667)
    at android.app.ActivityThread.access$1500(ActivityThread.java:117)
    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:935)
    at android.os.Handler.dispatchMessage(Handler.java:99)
    at android.os.Looper.loop(Looper.java:123)
    at android.app.ActivityThread.main(ActivityThread.java:3687)
    at java.lang.reflect.Method.invokeNative(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:507)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:867)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:625)
    at dalvik.system.NativeStart.main(Native Method)
Andro Selva
  • 53,910
  • 52
  • 193
  • 240
Farid Ala
  • 668
  • 1
  • 12
  • 30

2 Answers2

1

You really have to check the devices you're willing to support. See

/data/ 

and check if you have the corresponding table. I've been there, and some devices really differ in terms of package naming, etc.

You can use an app something like, aSQLiteManager to browse schemas.

Other useful sources:

Debugging sqlite database on the device

Android: Where are database files stored?

Community
  • 1
  • 1
setzamora
  • 3,560
  • 6
  • 34
  • 48
  • Thank you very much for your reply. I used String DB_PATH = "/data/data/english.idiom/databases/ . Does this File dbFile = getDatabasePath(MY_DB_NAME); work? – Farid Ala Jan 24 '12 at 10:16
0

My question is: do you have other SQL errors in ACRA logs? Particularly, about database corruption?

In my question: Better SQLite corruption detection I presented the quick analysis of SQLite behavior when DB file was randomly modified. When "SELECT *" was failing, sometimes SQLite claimed that it was because the table didn't exist. When I loaded the modified DB file into editor, all tables were missing - so, random modification of the DB file may actually erase all your tables.

Community
  • 1
  • 1
user1234567
  • 1,832
  • 1
  • 18
  • 25