views:

60

answers:

3

I'm trying to debug an issue myself. May post it later if I fail ;-)

My logcat log states "android.database.CursorIndexOutOfBoundsException: Index -1 requested, with a size of 2"

I would like to use log.v("desc", cursor) to show what the cursor returns. Is there a way to specify a value from it like cursor[0] ?

+2  A: 

Have you called moveToFirst() on Cursor?

Gawcio
Thank you, that solved my problem. Now on to the next one, yay! You're a star!
Amit
A: 

Or if you're looking for where the cursor is at a specific point in time, call Cursor.getPosition()

Take a look at the Cursor API.

It's often very wordy, but sometimes it helps.

komidore64
A: 

If you intend to write contents of the cursor to the logcat row by row you can use code as below:

if (cursor.moveToFirst()) {
    do {
        StringBuilder sb = new StringBuilder();
        int columnsQty = cursor.getColumnCount();
        for (int idx=0; idx<columnsQty; ++idx) {
            sb.append(cursor.getString(idx));
            if (idx < columnsQty - 1)
                sb.append("; ");
        }
        Log.v(TAG, String.format("Row: %d, Values: %s", cursor.getPosition(), sb.toString()));
    while (cursor.moveToNext());
}

As I don't have IDE on the computer I'm not able to check if it ever compiles. But I hope it does :)

Gawcio