lundi 8 juin 2015

ursorIndexOutOfBoundsException: Index 1 requested, with a size of 1

I want to increase two integers for every entry in my SQLite database where the critical variable is 5 or 1 (two seperate tables). Unfortunately I can not start the Activity and get this error:

android.database.CursorIndexOutOfBoundsException: Index 1 requested, with a size of 1
Caused by: android.database.CursorIndexOutOfBoundsException: Index 1 requested, with a size of 1

In the table of getUpload there is only one entry but how can I prevent it from crashing even there are only 1 or 0 entrys in the table?

dbh  = new DbHelper(context);
    cursor = dbh.getScore(dbh);
    cursor.moveToFirst();
    if (cursor.moveToFirst()) {
        do {
            if (Integer.parseInt(cursor.getString(0)) == 5){
                points++;
            }
        }
        while(cursor.moveToNext());
    }
    cursor.close();

    c = dbh.getUpload(dbh);
    c.moveToFirst();
    if (c.moveToFirst()) {
        do {
            if (Integer.parseInt(cursor.getString(0)) == 1){
                uploadPoints++;
            }
        }
        while(c.moveToNext());
    }
    c.close();

Aucun commentaire:

Enregistrer un commentaire