Search code examples
androidsqliteillegalstateexceptionandroid-cursor

Android - SQLite Cursor getColumnIndex() is case sensitive?


While working with SQLiteCursor in Android I came to know that the getColumnIndex() is behaving case sensitive for example:

Example:

Column Name in DB was: Rules

cursor.getColumnIndex("Rules")  //works fine
cursor.getColumnIndex("rules")  //throws error, see the error detail

The documentation says nothing about that, for detail please see this.

LogCat says:

java.lang.IllegalStateException: Couldn't read row 0, col -1 from CursorWindow. Make sure the Cursor is initialized correctly before accessing data from it

I am confused by this behavior of SQLiteCursor, can someone help me that this is true OR I am doing something wrong? I can provide the code if required.

Thanks.


Solution

  • getColumnIndex() is case sensitive:

    Column Name in DB was: Rules

    cursor.getColumnIndex("Rules") //workes fine

    cursor.getColumnIndex("rules") //throws error, see the error detail