I am trying to insert a value into a SQLite table, but when I fetch that value, it looks like null is getting inserted instead.
The call to insert the row is given as:
@Override
public void onClick(View v) {
Deck deck = new Deck(mDeckNameText.getText().toString());
db.addDeck(deck);
}
The addDeck method in to insert the row (which is in my database handler) is as follows:
void addDeck(Deck deck) {
SQLiteDatabase db = this.getWritableDatabase();
ContentValues values = new ContentValues();
values.put(KEY_DECK_NAME, deck.getDeckName());
db.insert(TABLE_DECKS,null,values);
}
Where the Deck class is defined as:
public class Deck {
int _deck_id;
String _deck_name;
public Deck(){
}
public Deck(String deck_name) {
this._deck_name = deck_name;
}
public Deck(int deck_id, String deck_name) {
this._deck_id = deck_id;
this._deck_name = deck_name;
}
//get deck_id
public int getDeckId(){
return this._deck_id;
}
//set deck_id
public void setDeckId(int deck_id){
this._deck_id = deck_id;
}
//get deck name
public String getDeckName(){
return this._deck_name;
}
//set deck name
public void setDeckName(String deck_name){
this._deck_name = deck_name;
}
}
The table that contains the decks is created in the following method:
public void onCreate(SQLiteDatabase db) {
String CREATE_DECKS_TABLE = "CREATE TABLE "+TABLE_DECKS+"("
+KEY_DECK_ID+" INTEGER PRIMARY KEY, "+KEY_DECK_NAME
+" TEXT"+")";
db.execSQL(CREATE_DECKS_TABLE);
}
The log output I get when I fetch the deck ids and deck names from the rows in my table looks something like this (after the third attempt at inserting a deck):
D/ID:﹕ 1
D/Name:﹕ null
D/ID:﹕ 2
D/Name:﹕ null
D/ID:﹕ 3
D/Name:﹕ null
Any idea why the name is coming back as null?
Thank you in advance.
Aucun commentaire:
Enregistrer un commentaire