I am getting this error when trying to retrieve all the entries of a table on the local database:
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.contactappca2/com.example.contactappca2.ViewActivity}: java.lang.IllegalStateException: Couldn't read row 0, col 0 from CursorWindow. Make sure the Cursor is initialized correctly before accessing data from it.
Caused by: java.lang.IllegalStateException: Couldn't read row 0, col 0 from CursorWindow. Make sure the Cursor is initialized correctly before accessing data from it.
This is my method inside my DbAdapter class where I retrieve the entries:
public List<Contact>getAllContacts(){
contacts = new ArrayList<Contact>();
cursor = db.query(TABLE_NAME, new String [] {COLUMN_NAME, COLUMN_NUMBER, COLUMN_EMAIL, COLUMN_IMG}, null,null,null,null,null);
if(cursor.moveToFirst()){
do{
c = new Contact();
c.setName(cursor.getString(0), null);
c.setNumber(cursor.getString(1));
c.setEmail(cursor.getString(2));
byte [] blob = cursor.getBlob(cursor.getColumnIndex(COLUMN_IMG));
ByteArrayInputStream inputStream = new ByteArrayInputStream(blob);
Bitmap b = BitmapFactory.decodeStream(inputStream);
c.setPicture(b);
contacts.add(c);
}while(cursor.moveToNext());
}
return contacts;
}
Any Idea what I am doing wrong? Many thanks.