Android Cursor strange behaviour

Posted by sandis on Stack Overflow See other posts from Stack Overflow or by sandis
Published on 2010-05-06T09:38:13Z Indexed on 2010/05/06 12:18 UTC
Read the original article Hit count: 261

Filed under:
|
|

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,

© Stack Overflow or respective owner

Related posts about android

Related posts about cursor