I'm trying to insert the contents of a Table into sqlite
within a listview
. The table in Sqlite is already filled, the listview was being filled with result of webservice
, which also works ok, however I am saving the values in a Sqlite so the query is faster the next time the user accesses. The following error appears in logcat when trying to insert into listview:
java.lang.IllegalStateException: could not read row 0, col -1 from CursorWindow. Make sure the Cursor is initialized correctly before accessing data from it.
Follow the code below and the error happens in the line categoria_produtoList.add(0, member);
public List<Ac_Df_Produto_Categoria> getAll() {
List<Ac_Df_Produto_Categoria> foos = new ArrayList< Ac_Df_Produto_Categoria>();
Ac_Df_Produto_Categoria member = null;
SQLiteDatabase db = this.getWritableDatabase();
Cursor c = null;
try {
c = db.rawQuery("Select * FROM " + NOME_TABELA_TERMOS_USO, null);
if (c.moveToFirst()) {
do {
member = new Ac_Df_Produto_Categoria();
member.setId(c.getInt(c.getColumnIndex("id")));
member.setPCT_ID(c.getInt(c.getColumnIndex("PCT_ID")));
member.setDescricaoInternet(c.getString(c.getColumnIndex("DescricaoInternet")));
member.setPossui_tamanho(c.getString(c.getColumnIndex("Possui_tamanho")));
foos.add(member);
Log.d("Categoria",c.getString(c.getColumnIndex("DescricaoInternet")));
categoria_produtoList.add(0, member);
adapter.notifyDataSetChanged();
swipeRefreshLayout.setRefreshing(true);
} while (c.moveToNext());
}
return foos;
}
finally {
if (c != null) {
c.close();
}
}
}