vendredi 30 octobre 2015

android.database.sqlite.SQLiteException: no such column: coin (code 1): , while compiling: SELECT attrib FROM table

i am using Sqlite database android and i got this this problem Caused by: android.database.sqlite.SQLiteException: no such column: coin (code 1): , while compiling: SELECT _id, name, age, coin, log FROM person_tb1 WHERE name = ?

i have no idea why it show me this !

i have tried it before its working fine !

here is the code where it says the problem :

public ArrayList<Person> getPersons (){

    persons.clear();

    SQLiteDatabase dba = this.getReadableDatabase();

    Cursor cursor = dba.query(Constants.TABLE_NAME,
            new String[]{Constants.KEY_ID, Constants.NAME, Constants.AGE , Constants.COIN , Constants.LOG},null,null,null,null,null);

    if(cursor.moveToFirst()){
        do {
            Person p = new Person();
            p.setName(cursor.getString(cursor.getColumnIndex(Constants.NAME)));
            p.setAge(cursor.getInt(cursor.getColumnIndex(Constants.AGE)));
            p.setCoin(cursor.getInt(cursor.getColumnIndex(Constants.COIN)));
            p.setLog(cursor.getInt(cursor.getColumnIndex(Constants.LOG)));
            p.setPersonId(cursor.getInt(cursor.getColumnIndex(Constants.KEY_ID)));

            persons.add(p);

        }while (cursor.moveToNext());

        cursor.close();
        dba.close();
    }
    return persons;
}

and here the select method :

 public void onCreate(SQLiteDatabase db) {
    String CREATE_TABLE = "CREATE TABLE " + Constants.TABLE_NAME + "(" +
            Constants.KEY_ID + " INTEGER PRIMARY KEY, " + Constants.NAME + " TEXT, "+
            Constants.AGE + " INT, " + Constants.COIN + " INT, " + Constants.LOG + " INT);";

    db.execSQL(CREATE_TABLE);
}

Aucun commentaire:

Enregistrer un commentaire