查看 Android 数据库游标

发布于 2024-10-03 17:50:22 字数 204 浏览 0 评论 0原文

有人知道如何在调试期间查看光标中的内容,以便确定数据库助手的功能吗?

它一直表现得像在返回数据,但是当我尝试使用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

樱娆 2024-10-10 17:50:22

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.

伴我老 2024-10-10 17:50:22

如果这是空指针异常,那么看来你的光标确实是空的。

我会使用 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文