0

我是 android 的新手,我上次在我的 android 应用程序中连接数据库,现在我在另一个项目中暗示它,但我收到了这些错误

    12-14 23:58:07.459: E/SQLiteLog(2171): (1) no such table: Quiz
    12-14 23:58:07.459: D/AndroidRuntime(2171): Shutting down VM
    12-14 23:58:07.459: W/dalvikvm(2171): threadid=1: thread exiting with                    uncaught               exception (group=0x40a13300)
    12-14 23:58:07.509: E/AndroidRuntime(2171): FATAL EXCEPTION: main
    12-14 23:58:07.509: E/AndroidRuntime(2171): java.lang.RuntimeException: Unable to         start activity   ComponentInfo{com.example.whowantto/com.example.whowantto.play}:       android.database.sqlite.SQLiteException: no such table: Quiz (code 1): , while compiling:   SELECT Question, OptionA, OptionB, OptionC, OptionD, CorrectAnswer FROM Quiz WHERE flag=0
    12-14 23:58:07.509: E/AndroidRuntime(2171):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2059)
    12-14 23:58:07.509: E/AndroidRuntime(2171):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2084)
    12-14 23:58:07.509: E/AndroidRuntime(2171):     at android.app.ActivityThread.access$600(ActivityThread.java:130)
    12-14 23:58:07.509: E/AndroidRuntime(2171):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1195)
    12-14 23:58:07.509: E/AndroidRuntime(2171):     at android.os.Handler.dispatchMessage(Handler.java:99)
    12-14 23:58:07.509: E/AndroidRuntime(2171):     at android.os.Looper.loop(Looper.java:137)
    12-14 23:58:07.509: E/AndroidRuntime(2171):     at android.app.ActivityThread.main(ActivityThread.java:4745)
    12-14 23:58:07.509: E/AndroidRuntime(2171):     at java.lang.reflect.Method.invokeNative(Native Method)
    12-14 23:58:07.509: E/AndroidRuntime(2171):     at java.lang.reflect.Method.invoke(Method.java:511)
    12-14 23:58:07.509: E/AndroidRuntime(2171):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
    12-14 23:58:07.509: E/AndroidRuntime(2171):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
    12-14 23:58:07.509: E/AndroidRuntime(2171):     at dalvik.system.NativeStart.main(Native Method)
    12-14 23:58:07.509: E/AndroidRuntime(2171): Caused by: android.database.sqlite.SQLiteException: no such table: Quiz (code 1): , while compiling: SELECT Question, OptionA, OptionB, OptionC, OptionD, CorrectAnswer FROM Quiz WHERE flag=0
    12-14 23:58:07.509: E/AndroidRuntime(2171):     at android.database.sqlite.SQLiteConnection.nativePrepareStatement(Native Method)
   12-14 23:58:07.509: E/AndroidRuntime(2171):  at android.database.sqlite.SQLiteConnection.acquirePreparedStatement(SQLiteConnection.java:882)
   12-14 23:58:07.509: E/AndroidRuntime(2171):  at android.database.sqlite.SQLiteConnection.prepare(SQLiteConnection.java:493)
   12-14 23:58:07.509: E/AndroidRuntime(2171):  at android.database.sqlite.SQLiteSession.prepare(SQLiteSession.java:588)
  12-14 23:58:07.509: E/AndroidRuntime(2171):   at android.database.sqlite.SQLiteProgram.<init>(SQLiteProgram.java:58)
   12-14 23:58:07.509: E/AndroidRuntime(2171):  at android.database.sqlite.SQLiteQuery.<init>(SQLiteQuery.java:37)
   12-14 23:58:07.509: E/AndroidRuntime(2171):  at android.database.sqlite.SQLiteDirectCursorDriver.query(SQLiteDirectCursorDriver.java:44)
   12-14 23:58:07.509: E/AndroidRuntime(2171):  at android.database.sqlite.SQLiteDatabase.rawQueryWithFactory(SQLiteDatabase.java:1314)
   12-14 23:58:07.509: E/AndroidRuntime(2171):  at android.database.sqlite.SQLiteDatabase.queryWithFactory(SQLiteDatabase.java:1161)
   12-14 23:58:07.509: E/AndroidRuntime(2171):  at android.database.sqlite.SQLiteDatabase.query(SQLiteDatabase.java:1032)
   12-14 23:58:07.509: E/AndroidRuntime(2171):  at android.database.sqlite.SQLiteDatabase.query(SQLiteDatabase.java:1238)
   12-14 23:58:07.509: E/AndroidRuntime(2171):  at com.example.whowantto.play.GetQuestion(play.java:479)
   12-14 23:58:07.509: E/AndroidRuntime(2171):  at com.example.whowantto.play.onCreate(play.java:142)
   12-14 23:58:07.509: E/AndroidRuntime(2171):  at android.app.Activity.performCreate(Activity.java:5008)
   12-14 23:58:07.509: E/AndroidRuntime(2171):  at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1079)
   12-14 23:58:07.509: E/AndroidRuntime(2171):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2023)
   12-14 23:58:07.509: E/AndroidRuntime(2171):  ... 11 more
   12-14 23:58:15.591: E/Trace(2195): error opening trace file: No such file or directory (2)

我已经检查了测验表,它存在于我的数据库中。提前谢谢

4

2 回答 2

1

问题是您使用模式创建了数据库,然后使用不同的模式查询它。要解决此问题,您可以

1)删除数据库,然后使用正确的模式再次创建它。

2)或者您可以更改数据库的版本号,

3)或者您可以将查询更改为SELECT * FROM Quiz WHERE flag = 0将选择所有列(我不确定 Quiz 表是否存在,这可能是一个问题)

于 2012-12-14T07:07:54.403 回答
1

更改您的数据库名称并运行它。有时您在数据库中插入额外的列意味着它会出现问题或检查您使用的查询。

光标 cur = DB.rawQuery("SELECT * FROM " + table_name, null);

希望这有用

于 2012-12-14T07:08:24.780 回答