查看 Android 数据库游标
有人知道如何在调试期间查看光标中的内容,以便确定数据库助手的功能吗?
它一直表现得像在返回数据,但是当我尝试使用 cursor.isNull(0)
方法时,我不断抛出 NullPointerException
并且无法看到什么单步执行时光标在其中确实让我感到沮丧。
任何帮助将不胜感激。
谢谢。
Would anyone know how I can view what a cursor has in it during debugging so that I can determine the functionality of my database helper?
It keeps acting like it's returning data, but then when I attempt to use the cursor.isNull(0)
method, I keep getting NullPointerException
thrown and not being able to see what the cursor has in it while stepping through the execution is really frustrating me.
Any help would be extremely appreciated.
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
Android 提供了一个专门的类来调试 Cursors。它称为 DatabaseUtils。
调用方法
DatabaseUtils.dumpCursorToString (光标)
查看光标的内容。这个助手循环并为您打印出 Cursor 的内容,并将光标返回到其原始位置,这样它就不会扰乱您的迭代逻辑。
Android has provided a specific class just for debugging Cursors. It is called DatabaseUtils.
Call the method
DatabaseUtils.dumpCursorToString(cursor)
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.
如果这是空指针异常,那么看来你的光标确实是空的。
我会使用 Log.d() 来帮助调试我的光标,您只需创建一个辅助方法即可将光标的整行转储到 LogCat。
If that's null pointer exception, it seems your cursor really is null.
I would use
Log.d()
to help debug my cursors, you can simply create a helper method to dump the whole row of your cursor to LogCat.