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"
我的logcat日志声明“android.database.CursorIndexOutOfBoundsException:索引-1请求,大小为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] ?
我想使用log.v(“desc”,cursor)来显示游标返回的内容。有没有办法像游标[0]那样指定一个值?
5 个解决方案
#1
3
Have you called moveToFirst()
on Cursor?
你有没有在Cursor上调用moveToFirst()?
#2
58
Android has provided a specific class just for debugging Cursors. It is called DatabaseUtils.
Android提供了一个专门用于调试游标的类。它被称为DatabaseUtils。
Call the method dumpCursorToString() to view the contents of your cursor.
调用方法dumpCursorToString()来查看游标的内容。
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.
这个助手循环遍历并打印出Cursor的内容,并将光标返回到原始位置,这样就不会弄乱你的迭代逻辑。
#3
36
use this before cursor.moveToFirst()
在cursor.moveToFirst()之前使用它
Log.v("Cursor Object", DatabaseUtils.dumpCursorToString(cursor))
#4
7
If you intend to write contents of the cursor to the logcat row by row you can use code as below:
如果您打算逐行将游标内容写入logcat,可以使用如下代码:
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());
}
#5
0
Or if you're looking for where the cursor is at a specific point in time, call Cursor.getPosition()
或者,如果您正在寻找光标在特定时间点的位置,请调用Cursor.getPosition()
Take a look at the Cursor API.
看一下Cursor API。
It's often very wordy, but sometimes it helps.
它通常非常冗长,但有时它会有所帮助。
#1
3
Have you called moveToFirst()
on Cursor?
你有没有在Cursor上调用moveToFirst()?
#2
58
Android has provided a specific class just for debugging Cursors. It is called DatabaseUtils.
Android提供了一个专门用于调试游标的类。它被称为DatabaseUtils。
Call the method dumpCursorToString() to view the contents of your cursor.
调用方法dumpCursorToString()来查看游标的内容。
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.
这个助手循环遍历并打印出Cursor的内容,并将光标返回到原始位置,这样就不会弄乱你的迭代逻辑。
#3
36
use this before cursor.moveToFirst()
在cursor.moveToFirst()之前使用它
Log.v("Cursor Object", DatabaseUtils.dumpCursorToString(cursor))
#4
7
If you intend to write contents of the cursor to the logcat row by row you can use code as below:
如果您打算逐行将游标内容写入logcat,可以使用如下代码:
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());
}
#5
0
Or if you're looking for where the cursor is at a specific point in time, call Cursor.getPosition()
或者,如果您正在寻找光标在特定时间点的位置,请调用Cursor.getPosition()
Take a look at the Cursor API.
看一下Cursor API。
It's often very wordy, but sometimes it helps.
它通常非常冗长,但有时它会有所帮助。