I’m a noob to android and i am using a method to display a SQLite query. I want the row entry to display as row#, entryname, qty, amount (1. ferrari 2 $250,000), but instead it displays as (1. ferrari 2 null$250,000). I’m at my wits end because i can’t figure out why i’m getting this pesky null. Nothing obvious jumps out at me in either my create entry or get data methods. Any help is greatly appreciated. Here is my code.
My create entry method:
public long createEntry(String coin, String quantity, String value) {
// TODO Auto-generated method stub
ContentValues cv = new ContentValues();
cv.put(KEY_NAME, coin);
cv.put(KEY_QUANTITY, quantity);
cv.put(KEY_VALUE, value);
return ourDatabase.insert(DATABASE_TABLE, null, cv);
}
My getdata method (for displaying in view):
public String getData() {
// TODO Auto-generated method stub
String[] columns = new String[]{ KEY_ROWID, KEY_NAME, KEY_QUANTITY, KEY_VALUE };
Cursor c = ourDatabase.query(DATABASE_TABLE, columns, null, null, null, null, null);
String result = "";
int iRow = c.getColumnIndex(KEY_ROWID);
int iName = c.getColumnIndex(KEY_NAME);
int iQuantity = c.getColumnIndex(KEY_QUANTITY);
int iValue = c.getColumnIndex(KEY_VALUE);
for (c.moveToFirst(); !c.isAfterLast(); c.moveToNext()){
result = result + c.getString(iRow) + " " + c.getString(iName) + " " + c.getString(iQuantity) + " " + c.getString(iValue) + "\n";
}
return result;
}
Well from your question, if what you are expecting is 4 results separated by spaces then in the following…
…you clearly have exactly that. If your create / get methods are OK then I’d start by suspecting your data source for the ‘value’.
The ‘null’ is pre-pended to the value, in other words, it appears after the third space. Take a close look at the encoding of your data source and make sure you are handling it correctly.