dimanche 3 avril 2016

getString in SQlite database returns only one row [duplicate]

This question already has an answer here:

I use the following query to return a column of names into a cursor:

db=openOrCreateDatabase("likescounter4",MODE_PRIVATE,null);
    Cursor c2=db.rawQuery("select name from liketable",null);
    c2.moveToFirst();
    names[0]=c2.getString(0);

The string names[0] contains the first value in the table and works fine. However, when i try this line:

names[1]=c2.getString(1);

an exception is shown which states:

java.lang.IllegalStateException: Couldn't read row 0, col 1 from CursorWindow

I checked the database and im sure it has more than one rows. What is the possible reason for this error?

Aucun commentaire:

Enregistrer un commentaire