Android 光标奇怪的行为

发布于 2024-08-31 21:38:18 字数 1163 浏览 1 评论 0原文

经过在大型应用程序中进行多个小时的错误搜索后,我终于找到了该错误。此日志记录捕获了问题:

Log.d(TAG,"buildList, DBresult.getInt(1): "+DBresult.getInt(1));
Log.d(TAG,"buildList, DBresult.getString(1): "+DBresult.getString(1));
Log.d(TAG,"buildList, DBresult.getInt(4): "+DBresult.getInt(4));
Log.d(TAG,"buildList, DBresult.getString(4): "+DBresult.getString(4));

结果输出:

05-06 11:11:20.123: DEBUG/TodoList(18943): buildList, DBresult.getInt(1): 0
05-06 11:11:20.123: DEBUG/TodoList(18943): buildList, DBresult.getString(1): false
05-06 11:11:20.123: DEBUG/TodoList(18943): buildList, DBresult.getInt(4): 0
05-06 11:11:20.123: DEBUG/TodoList(18943): buildList, DBresult.getString(4): true

没有正在运行的后台线程。正如您所看到的,问题在于“0”在某种情况下被解释为 false,而在另一种情况下被解释为 true。由于我完全不知道这是如何发生的,所以我不知道如何继续。什么可能导致这种行为?两列都是“布尔”类型,即 sqlite 中的数字。不幸的是,返回的字符串是正确的值,而整数始终为 0。如果我将数据库导出到我的计算机并使用 SQlite Administrator 检查它,我可以看到值设置正确,只有 getInt() 函数总是返回 0。我知道这在我编写的其他应用程序中有效,但我不知道为什么它停止工作。

我尝试过在2.0、2.0.1和2.1下编译代码,它总是出现。我可以通过获取如下布尔值来使我的应用程序再次运行:

myBool= (DBresult.getString(0).equals("true"));

但这既丑陋又没有优化。欢迎就导致此行为的原因提供任何建议。

干杯,

After many houres of bug searching in a big app, I have finally tracked down the bug. This logging captures the problem:

Log.d(TAG,"buildList, DBresult.getInt(1): "+DBresult.getInt(1));
Log.d(TAG,"buildList, DBresult.getString(1): "+DBresult.getString(1));
Log.d(TAG,"buildList, DBresult.getInt(4): "+DBresult.getInt(4));
Log.d(TAG,"buildList, DBresult.getString(4): "+DBresult.getString(4));

The resulting output:

05-06 11:11:20.123: DEBUG/TodoList(18943): buildList, DBresult.getInt(1): 0
05-06 11:11:20.123: DEBUG/TodoList(18943): buildList, DBresult.getString(1): false
05-06 11:11:20.123: DEBUG/TodoList(18943): buildList, DBresult.getInt(4): 0
05-06 11:11:20.123: DEBUG/TodoList(18943): buildList, DBresult.getString(4): true

There are no backgroung threads running. As you can see the problem is that '0' is interpreted as false on one occasion, and as true on another. Since I am completely lost on how this can happen, I dont know how to proceed. What could possibly result in such a behaviour? Both the columns are of the type "boolean", i.e a numeric in sqlite. Unfortunately the string returned is the correct value, while the integer is always 0. If I export the database to my computer and check it with SQlite Administrator I can see that the values are correctly set, it is only the getInt()-function that always returns 0. I know for a fact that this works in other apps I have coded, and I dont know why this has stopped working.

I have tried compiling the code under 2.0, 2.0.1 and 2.1, and it always appears. I can make my app runnable again by getting boolean values like this:

myBool= (DBresult.getString(0).equals("true"));

but that is both ugly and not optimized. Any suggestions on what is causing this behaviour is welcome.

Cheers,

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(1

峩卟喜欢 2024-09-07 21:38:18

我相信我解决了它:
更新数据库接口后,插入之前的所有数据都通过 String.valueOf() 函数转换为字符串。因此,数据库中输入的不是“1”,而是“true”。我的数据库管理工具没有显示出差异。我不知道为什么用 getInt() 函数将其转换为“0”,但这似乎是问题所在。

I do believe I solved it:
After an update to the database interface all data before insertion was converted to string via String.valueOf()-function. So instead of "1", "true" was input into the database. The difference was not shown with my databas management-tools. Why this is coverted to '0' with the getInt()-function I do not know, but this seems to be the problem.

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