mercredi 3 juin 2015

Column not found - Sqlite Andriod

I searched around here too much but couldn't able to resolve the errors !!

I have marjorly 2 classes

public class DatabaseOperation extends SQLiteOpenHelper{
    private static final int DATABASE_VERSION = 2;

    public String QUERY = "CREATE TABLE " + TableData.TableInfo.TABLE_NAME +"("+ TableData.TableInfo.USER_NAME+"TEXT,"+
            TableData.TableInfo.USER_EMAIL+"TEXT,"+ TableData.TableInfo.USER_NUMBER+"TEXT );";
    public DatabaseOperation(Context context){
        super(context, TableData.TableInfo.DATABASES_NAME,null,DATABASE_VERSION);
    }
    @Override
    public void onCreate(SQLiteDatabase db){
        db.execSQL(QUERY);
    }
    @Override
    public void onUpgrade(SQLiteDatabase db,int oldVersion,int newVersion){

    }
    public void putInfo(DatabaseOperation dop,String name,String email,String pass,String no){
        SQLiteDatabase sq = dop.getWritableDatabase();
        ContentValues cv = new ContentValues();
        cv.put(TableData.TableInfo.USER_NAME,name);
        cv.put(TableData.TableInfo.USER_EMAIL,email);
        cv.put(TableData.TableInfo.USER_NUMBER,no);
//        cv.put(TableData.TableInfo.USER_PASS,pass);
        cv.put(TableData.TableInfo.USER_STATE,"Available");
        long k = sq.insert(TableData.TableInfo.TABLE_NAME,null,cv);
    }

    public boolean seacrhEmail(DatabaseOperation db,String email){

        return true;
    }
}

and

public class TableData {

    public static abstract class TableInfo implements BaseColumns{
        public static final String USER_NAME = "user_name";
        public static final String USER_EMAIL = "user_eMail";
//        public static final String USER_PASS = "user_pass";
        public static final String USER_NUMBER = "user_phNumber";
        public static final String DATABASES_NAME = "user_info";
        public static final String TABLE_NAME = "taxi_registration";
        public static final String USER_STATE = "taxi_state";
    }
}

Error when I run insert statement

06-03 21:57:26.459    3700-3700/com.example.jawad.testapplication E/SQLiteLog﹕ (1) table taxi_registration has no column named user_name
06-03 21:57:26.475    3700-3700/com.example.jawad.testapplication E/SQLiteDatabase﹕ Error inserting user_name=bb user_eMail=bb@z.n taxi_state=Available user_phNumber=666
    android.database.sqlite.SQLiteException: table taxi_registration has no column named user_name (code 1): , while compiling: INSERT INTO taxi_registration(user_name,user_eMail,taxi_state,user_phNumber) VALUES (?,?,?,?)
            at android.database.sqlite.SQLiteConnection.nativePrepareStatement(Native Method)
            at android.database.sqlite.SQLiteConnection.acquirePreparedStatement(SQLiteConnection.java:893)
            at android.database.sqlite.SQLiteConnection.prepare(SQLiteConnection.java:504)
            at android.database.sqlite.SQLiteSession.prepare(SQLiteSession.java:588)
            at android.database.sqlite.SQLiteProgram.<init>(SQLiteProgram.java:58)
            at android.database.sqlite.SQLiteStatement.<init>(SQLiteStatement.java:31)
            at android.database.sqlite.SQLiteDatabase.insertWithOnConflict(SQLiteDatabase.java:1492)
            at android.database.sqlite.SQLiteDatabase.insert(SQLiteDatabase.java:1364)
            at com.example.jawad.testapplication.d.a(Unknown Source)
            at com.example.jawad.testapplication.r.onClick(Unknown Source)
            at android.view.View.performClick(View.java:4463)
            at android.view.View$PerformClick.run(View.java:18770)
            at android.os.Handler.handleCallback(Handler.java:808)
            at android.os.Handler.dispatchMessage(Handler.java:103)
            at android.os.Looper.loop(Looper.java:193)
            at android.app.ActivityThread.main(ActivityThread.java:5292)
            at java.lang.reflect.Method.invokeNative(Native Method)
            at java.lang.reflect.Method.invoke(Method.java:515)
            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:824)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:640)
            at dalvik.system.NativeStart.main(Native Method)

I followed this tutorial ... I don't know what I missed ...

PS: I am bit new to andriod.

Aucun commentaire:

Enregistrer un commentaire