Asaf Nevo
Asaf Nevo

Reputation: 11678

Cursor.moveToNext() return false while Cursor.getCount() says that are more than 1 row

I'm running a query in the my Sqlite DB..

I'm saving the results in my Cursor, and i'm iterating through it in order to get all results..

allotugh i'm checking and seeing that the cursor has more than 1 row, it only gives me the first row since the moveToNext() always return false..

This is my iterate code:

Cursor cursor = getEventsDetails(db, selection, null);              
Log.e("cursor before", "count"  + cursor.getCount());
boolean moveToNext = cursor.moveToFirst();
if (moveToNext)
{
    do 
    {                               

        //Create a new PicoEvent instance with the event's details
        PicoEvent event = PicoEventCreator.createPicoEvent(cursor);         
        Log.e(event.getName(), event.getStartTime().toLocaleString());
        Log.e("cursor in", "count"  + cursor.getCount());
        moveToNext = cursor.moveToNext();
        Log.e("moveToNext", "move: " + moveToNext);
        if (!isEventExists(eventsList, event))
            eventsList.add(event);
    } while (moveToNext);
}   

This is the Logcat Debug:

12-01 17:33:07.774: E/cursor before(5950): count4
12-01 17:33:08.094: E/Pico Demo Event(5950): 1 בדצמ 2013 11:00:00
12-01 17:33:08.124: E/cursor in(5950): count4
12-01 17:33:08.124: E/moveToNext(5950): move: false

As you can see the row count is 4, but yet the move is false...

Upvotes: 4

Views: 1555

Answers (1)

David Wasser
David Wasser

Reputation: 95578

You are passing this Cursor to another method in this call:

PicoEvent event = PicoEventCreator.createPicoEvent(cursor);

I'll bet that method is advancing the cursor to the end before it returns.

Upvotes: 1

Related Questions