When my application is creating the database, it seems to not be creating the column 'cardname'. I've been looking through my code but can't find what I've done wrong. Can anyone help me please ?
DBAdapter class
static final String DATABASE_CREATE =
"create table Users (_id integer primary key autoincrement, "
+ "name text not null,"
+"password text not null,"
+"cardnum text not null,"
+ "cardname text not null"
+ ");";
The query inside the DBAdapter class
//--retrieves cards for the user--
public Cursor getCards(String username) throws SQLException{
Cursor mCursor =
db.query(true, DATABASE_TABLE, new String[] {KEY_ROWID, KEY_USERNAME, KEY_CARDNAME}, KEY_USERNAME + "= '" + username + "'", null, null, null, null,null);
if (mCursor != null) {
mCursor.moveToFirst();
}
return mCursor;
}
Main Activity Class (When the error occurs) ..
if (view.getId() == R.id.bttn_show)
{
EditText username = (EditText) findViewById(R.id.tf_username);
String tesco = "tesco";
DBAdapter db= new DBAdapter(this);
db.open();
Cursor c = db.getCards(username.getText().toString());
ArrayList<String> usersCards = new ArrayList<>();
if(c.moveToFirst()) {
do {
String aCard = c.getString(c.getColumnIndex("cardname"));
usersCards.add(aCard);
} while (c.moveToNext());
}
if (usersCards.contains(tesco)) {
ImageButton tb1 = (ImageButton) findViewById(R.id.ib_1);
tb1.setBackgroundResource(R.drawable.tesco);
}
else {
Toast.makeText(this, "Please Add a Card", Toast.LENGTH_LONG).show();
}
}
Logcat error log
02-07 12:44:54.680 2153-2153/com.cardpocket.cardpocket E/SQLiteLog﹕ (1) no such column: cardname
Caused by: android.database.sqlite.SQLiteException: no such column: carddesc (code 1): , while compiling: SELECT DISTINCT _id, name, carddesc FROM Users WHERE name= 'cliff'
Thank you in advance.
Aucun commentaire:
Enregistrer un commentaire