IllegalStateException: Couldn't read row 0 error
So I'm stuck with this problem.
Here is my code:
public class CustomAdapter extends CursorAdapter
{
LayoutInflater inflater;
public CustomAdapter(Context context, Cursor c) {
super(context, c);
inflater = LayoutInflater.from(context);
}
@Override
public void bindView(View view, Context context, Cursor cursor) {
// TODO Auto-generated method stub
TextView tv1 = (TextView)view.findViewById(R.id.fullname);
TextView tv2 = (TextView)view.findViewById(R.id.lastffup);
TextView tv3 = (TextView)view.findViewById(R.id.diagnosis);
Typeface tf = Typeface.createFromAsset(getAssets(),
"fonts/roboto-regular.ttf");
tv1.setTypeface(tf);
tv2.setTypeface(tf);
tv3.setTypeface(tf);
tv1.setText(cursor.getString(cursor.getColumnIndex(DBHelper.KEY_FNAME)));
tv2.setText(cursor.getString(cursor.getColumnIndex(DBHelper.KEY_LASTFFUP)));
tv3.setText(cursor.getString(cursor.getColumnIndex(DBHelper.KEY_DIAGNOSIS)));
}
@Override
public View newView(Context context, Cursor cursor, ViewGroup parent) {
return inflater.inflate(R.layout.custom_row, parent, false);
}
}
private void displayResults(){
dbHelper = new DBHelper(this);
try {
dbHelper.createDataBase();
} catch (IOException ioe) {
throw new Error("Unable to create database");
}
try {
dbHelper.openDataBase();
} catch (SQLException sqle) {
throw sqle;
}
Cursor cursor = dbHelper.getAllPatients();
String[] data = new String[]{
DBHelper.KEY_FNAME , DBHelper.KEY_DIAGNOSIS,
DBHelper.KEY_LASTFFUP};
int[] to = new int[] {R.id.fullname, R.id.diagnosis, R.id.lastffup};
// + "|| ' ' ||" + DBHelper.KEY_LNAME
//dataAdapter = new SimpleCursorAdapter(this, R.layout.custom_row,
cursor, data, to, 0);
//MyAdapter ca = new MyAdapter(this, R.layout.custom_row, cursor,
data, to);
CustomAdapter ca = new CustomAdapter(this, cursor);
lv.setAdapter(ca);
lv.setTextFilterEnabled(true);
dbHelper.close();
}
my cursor seems legit but I don't know what went wrong. Any help will much
be appreciated. Thanks.
No comments:
Post a Comment