samedi 26 septembre 2015

Android Sqlite Asset Helper : No such column Error

I have used SQLITEDB Browser and created
DATABASE : harryPotterDB.db
TABLENAME : PotterQuizCollection (Question,Option1,Ans,QID)

Database is situated as assets/databases/harryPotterDB.db

The error occured is android.database.sqlite.SQLiteException: no such column: Ans: , while compiling: SELECT 0 _id, Question, Option1, Ans FROM PotterQuizCollection I am able to access Option1 and Question Columns.

SQLiteDBHandler.java

                package com.example.sandeep.harrypotterquiz;

                import android.content.Context;
                import android.database.Cursor;
                import android.database.sqlite.SQLiteDatabase;
                import android.database.sqlite.SQLiteQueryBuilder;
                import android.util.Log;

                import com.readystatesoftware.sqliteasset.SQLiteAssetHelper;

                public class SQLiteDBHandler extends SQLiteAssetHelper
                {
                    private static final String TAG = "mytag";
                    private static final String DATABASE_NAME = "harryPotterDB.db";
                    private static final int DATABASE_VERSION = 1;

                    public SQLiteDBHandler(Context context)
                    {
                        super(context, DATABASE_NAME, null, DATABASE_VERSION);
                    }


                    public  void/*String[]*/  getQuestion(int qCounter)
                    {
                        /**********VARIABLE SECTION STARTS************/
                        SQLiteDatabase db = getReadableDatabase();
                        SQLiteQueryBuilder qb = new SQLiteQueryBuilder();
                        String questionDetails[]=new String[6];
                        int arrayPtr=0;
                        /**********VARIABLE SECTION ENDS************/

                        String [] sqlSelect = {"0 _id","Question","Option1","Ans"};
                        String sqlTables = "PotterQuizCollection";

                        qb.setTables(sqlTables);
                        Log.d(TAG, "just before cursor");
                        Cursor c = qb.query(db, sqlSelect, null, null,
                                null, null, null);

                        Log.d(TAG, "just after cursor");
                        /****************************DATABASE ACCESS SECTION DONE. WE HAVE CURSOR C WITH US********************************************/

                        c.moveToFirst();
                        Log.d(TAG, c.getString(2));
                        /*
                    }
                }

LOGCAT

09-26 17:49:35.726  13487-13487/com.example.sandeep.harrypotterquiz I/Database? sqlite returned: error code = 1, msg = no such column: Ans
          09-26 17:49:35.742  13487-13487/com.example.sandeep.harrypotterquiz E/AndroidRuntime? FATAL EXCEPTION: main
          java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.sandeep.harrypotterquiz/com.example.sandeep.harrypotterquiz.QuizDisplay}: android.database.sqlite.SQLiteException: no such column: Ans: , while compiling: SELECT 0 _id, Question, Option1, Option2, Option3, Ans FROM PotterQuizCollection
          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:130)
          at android.app.ActivityThread.main(ActivityThread.java:3689)
          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:842)
          at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:600)
          at dalvik.system.NativeStart.main(Native Method)

Aucun commentaire:

Enregistrer un commentaire