metemet06
metemet06

Reputation: 1472

c.getString couldnt get field

c.getString(i+2) doesnt work; am I missed something with these codes ?

Error : java.lang.IllegalStateException: get field slot from row 0 col 13 failed

...

static String [] lesson_value;
    String query = "SELECT id, tag, lesson1, lesson2, lesson3, lesson4, lesson5," +
                    " lesson6, lesson7, lesson8, lesson9, lesson10,lesson11 " +
                    "from mytable order by id DESC limit 1";
            Cursor c = db.rawQuery(query,null);
            if (c != null && c.moveToFirst()) {
                    for(int i=0; i<12; i++) {
                 if ( c.getString(i+2) != null ) {
                     lesson_value[i] = c.getString(i+2);
}
}

Upvotes: 0

Views: 128

Answers (1)

paxdiablo
paxdiablo

Reputation: 882146

I'm pretty certain that 12 in the for loop should be an 11. There are 11 lessons, with indexes 2 through 12 inclusive and, since you're adding two, that would mean the index should range from 0 to 10 inclusive.

Or you can run the for loop from 2 through 12 inclusive without adding two:

for (i = 2; i <= 12; i++)
    justUse (i);

Upvotes: 3

Related Questions