Iteration of the cursor loop does not display the first value

So, I have a query that returns a cursor with all values ​​(I confirmed this with cursor.getCount (), where the returned int was equivalent to the number of records in the database), but for some reason no matter what iteration -loop is I write, I can never get the first value of a list.

private void addAllUnsentCrapportsToList() {
    mDbAdapter.open();
    Cursor cursor = mDbAdapter.getAllCrapports();
    cursor.moveToFirst();
    String text = "";
    while(cursor.isAfterLast() == false){
        text = text
                + "typ: " + cursor.getString(cursor.getColumnIndex(DbAdapter.CRAPPORT_KEY_GARBAGETYPE))
                + " kommentar: " + cursor.getString(cursor.getColumnIndex(DbAdapter.CRAPPORT_KEY_COMMENT))
                + "\n";
        cursor.moveToNext();
    }

    unsentCrapportList.setText(text);
}

This bit of code displays all values ​​except the first. What am I doing wrong? I tried many approaches, including doing, for now, etc., but always had the same error.

What am I missing?

+3
source share
4 answers

It turns out there was nothing wrong with the code. I had to “clean up the project” in Eclipse and then restart the emulator. Thanks to all the answers.

+1

if (cursor.moveToFirst()) {
    while (cursor.moveToNext()) {
        // Your code
    }
}
+1

. , db? cursor.moveToFirst();, , ?

+1
cursor.moveToFirst();
while (cursor.moveToNext()) {
    // Your code
}

. , ?

LOG, , , , http://sourceforge.net/projects/sqlitebrowser/

: Btw, - startManagingCursor(cursor);? , , , .

0

All Articles