Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Output values found in cursor to logcat? - Android

Tags:

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] ?

like image 290
Amit Avatar asked Jun 23 '10 20:06

Amit


2 Answers

Android has provided a specific class just for debugging Cursors. It is called DatabaseUtils.

Call the method dumpCursorToString() to view the contents of your cursor.

This helper loops through and prints out the content of the Cursor for you, and returns the cursor to its original position so that it doesn't mess up your iterating logic.

like image 132
Some Noob Student Avatar answered Oct 14 '22 15:10

Some Noob Student


use this before cursor.moveToFirst()

Log.v("Cursor Object", DatabaseUtils.dumpCursorToString(cursor))
like image 42
Zeeshan Avatar answered Oct 14 '22 16:10

Zeeshan