Reputation: 75
i try to query for all data in specific colum but result in error "make sure that cursor initialized correctly before accessing thedata". is there any problem with this code thank you.
public List<String> getAllItemName(){
String[] column = new String[]{Pro_ID, Pro_Name, Pro_Price, Pro_Description, Pro_Date};
Cursor c= ourDatabase.rawQuery("SELECT " + Pro_Name + " From "+ TABLE_NAME , null);
List<String> lst = new ArrayList<String>();
if (c.moveToFirst()) {
do {
lst.add(c.getString(1));
String name = c.getString(1);
Log.v(name,name + (" name"));
} while (c.moveToNext());
}
return lst;
}
Upvotes: 0
Views: 118
Reputation: 29436
Cursor Indexes are 0 based. First column corresponds to :c.getString(0)
.
You can get index of a column using getColumnIndex(columnName)
Upvotes: 2
Reputation: 145
Try this instead of c.getString(1):
c.getString(c.getColumnIndex(Pro_Name))
Upvotes: 3