我编写了一个使用SQLite数据库的Android应用程序,该数据库保存在assets文件夹中。 该数据库有4个表:“table1”,“table2”和“table3”以及“android_metadata”。该应用程序在大多数设备上运行良好,但已报告了一些崩溃。所以我使用acra(Android的应用程序崩溃报告,http://code.google.com/p/acra/)来收集日志。 我确信数据库有“table2”表,但是日志说没有这样的表。我真的很想知道为什么它在某些设备上工作正常,但在其他设备上崩溃了? 手机型号为三星GT-I9001GT,Android 2.3.3。一些HTC渴望HD也有这个问题。 请帮我解决一下。感谢。
日志
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)
答案 0 :(得分:1)
您必须检查您愿意支持的设备。参见
/data/
并检查您是否有相应的表格。我去过那里,有些设备在包命名等方面确实不同。
您可以使用类似aSQLiteManager之类的应用来浏览架构。
其他有用的资料来源:
答案 1 :(得分:0)
我的问题是:ACRA日志中是否有其他SQL错误?特别是关于数据库损坏?
在我的问题中:Better SQLite corruption detection我提出了随机修改DB文件时SQLite行为的快速分析。当“SELECT *”失败时,有时SQLite声称这是因为该表不存在。当我将修改后的DB文件加载到编辑器中时,所有表都丢失了 - 因此,随机修改DB文件实际上可能会删除所有表格。