Does a cursor in Android reference columns from 0 or 1?

后端 未结 3 2012
粉色の甜心
粉色の甜心 2021-01-18 03:50

I am working with an SQLite Database and I am returning cursors successfully but I was wondering if a cursor references columns starting with 0 like arrays or just 1?

3条回答
  •  忘掉有多难
    2021-01-18 04:32

    The Android documentation states that the getColumnIndex method from a SQLite Cursor returns the zero-based index for the given column name, or -1 if the column doesn't exist.

    If you expect the column to exist use getColumnIndexOrThrow(String) instead, which will make the error more clear.

    In short, they start at 0.

    Source:

    http://developer.android.com/reference/android/database/sqlite/SQLiteCursor.html#getColumnIndex(java.lang.String)

提交回复
热议问题