Android Cursor weird behavior

After many hours of searching for errors in a large application, I finally discovered an error. This log logs 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));

Result:

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

No streams backgroung. As you can see, the problem is that “0” is interpreted as a lie at one time and as truth on another. Since I completely lost how this can happen, I don’t know how to do it. What could lead to this behavior? Both columns are of type "boolean", i.e. Number in sqlite. Unfortunately, the correct line is correct, and the integer is 0. If I export the database to my computer and run it using SQlite Administrator, I see that the values ​​are set correctly, this is only the getInt () function that always returns 0. I know that this works in other applications that I encoded, and I don’t know why it stopped working.

I tried to compile the code under 2.0, 2.0.1 and 2.1, and it always appears. I can run the application again by receiving the following values:

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

, . , , .

,

+3
1

, : String.valueOf(). "1" "". . '0' getInt(), , , , .

+1

Source: https://habr.com/ru/post/1744312/


All Articles