将游标中找到的值输出到 logcat? - 安卓
我正在尝试自己调试问题。如果我失败了,可以稍后发布;-)
我的 logcat 日志状态 "android.database.CursorIndexOutOfBoundsException: Index -1 requests, with a size of 2"
我想使用 log.v ("desc",cursor)
显示光标返回的内容。有没有办法像cursor[0]一样从中指定一个值?
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] ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
Android 提供了一个专门的类来调试 Cursors。它称为 DatabaseUtils。
调用方法 dumpCursorToString() 查看光标的内容。
这个助手循环并为您打印出 Cursor 的内容,并将光标返回到其原始位置,这样它就不会扰乱您的迭代逻辑。
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.
在
cursor.moveToFirst()
之前使用它use this before
cursor.moveToFirst()
如果您打算将游标的内容逐行写入logcat,可以使用如下代码:
If you intend to write contents of the cursor to the logcat row by row you can use code as below:
您应该在 Cursor 上调用
moveToFirst()
。You should call
moveToFirst()
on Cursor.或者,如果您要查找光标在特定时间点的位置,请调用
Cursor.getPosition()
查看 光标 API。
它通常很啰嗦,但有时很有帮助。
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.