When executing a getter method to pull DB data into a GridView I get the following error:
Caused by: java.lang.IllegalStateException: Couldn't read row 0, col -1 from CursorWindow. Make sure the Cursor is initialized correctly before accessing data from it.
DBHelper class;
public List<Site> getAllSites(){
List<Site> sites = new ArrayList<Site>();
String selectQuery = "SELECT * FROM " + TABLE_SITES;
Log.e(LOG, selectQuery);
SQLiteDatabase database = this.getReadableDatabase();
Cursor c = database.rawQuery(selectQuery, null);
if (c.moveToFirst()){
do {
Site st = new Site();
st.setSiteID(c.getInt(c.getColumnIndex(KEY_SITE_ID))); //Error thrown here
st.setSiteName(c.getString(c.getColumnIndex(KEY_SITE_NAME)));
st.setSiteLat(c.getDouble(c.getColumnIndex(KEY_SITE_LAT)));
st.setSiteLon(c.getDouble(c.getColumnIndex(KEY_SITE_LON)));
st.setSiteCreatedDateTime(c.getString(c.getColumnIndex(KEY_CREATED_AT)));
sites.add(st);
} while (c.moveToNext());
}
return sites;
}
The error is thrown at:
siteList = db.getAllSites(); in MainActivity and at
st.setSiteID(c.getInt(c.getColumnIndex(KEY_SITE_ID))); in DBHelper class
Aucun commentaire:
Enregistrer un commentaire