user1846871
user1846871

Reputation: 68

Database connection in android

I am new in android I connect database in my android app last time and now i am implimenting that in another project but I got these error

    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)

I already check Quiz table it is peresent in my databse ..Thanks in advance

Upvotes: 0

Views: 388

Answers (2)

APriya
APriya

Reputation: 2004

Change your database name and run it. sometimes you insert extra columns in database means it will occur problem or check with query that you used.

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

Hope this useful

Upvotes: 1

CocoNess
CocoNess

Reputation: 4222

The problem is that you created the database with a schema, and then you are querying it with a different schema. To fix this you can either

1) delete the database, and then create it again with the correct schema.

2) Or you can change your version number of the DB,

3) Or you can change your query to SELECT * FROM Quiz WHERE flag = 0 which will select all columns (I'm not sure if the Quiz table exists, this could be a problem)

Upvotes: 1

Related Questions