jeudi 15 janvier 2015

Android: Error: Couldn't read row 1, col 1 from CursorWindow

My app is throwing me Exception


Error: Couldn't read row 1, col 1 from CursorWindow. Make sure the Cursor is initialized correctly before accessing data from it.


Here is my function:



static public String[] getData(Context ctx) {
String[] result = null;
try {
SQLiteDatabase db = ctx.openOrCreateDatabase("mydatabase", 0,
null);
Cursor c = db.query("answers", new String[]{"answer"}, "id_question='1'", null, null, null, null);
if (c.getCount() == 0) {
return null;
}

result = new String[c.getCount()];
c.moveToFirst();

for (int i = 0; i < c.getCount(); i++) {
result[i]=c.getString(i);
Log.v(TAG, "Answer "+c.getString(i));//responds just on 1st time
c.moveToNext();
}
c.close();
db.close();

return result;
} catch (Exception e) {
Log.e(TAG,
"Database.getData(Context) - Error: "
+ e.getMessage());
return result;
}
}


table structure:



db.execSQL("CREATE TABLE IF NOT EXISTS answers (id INTEGER PRIMARY KEY AUTOINCREMENT, "
+ "id_question VARCHAR, answer VARCHAR);");


When i put in coursor for serach just for column



  • "answer" result is [ttttt, null, null] - where ttttt is 1st answer

  • "id_question" result is [1, null, null]

  • null result is [1, 1, wwwww] - where 1 is id_question and wwww is last answer


what am I doing wrong? I wold appreciate any help. Thanks!


Aucun commentaire:

Enregistrer un commentaire