getColumnIndex(_ID)返回零,getlong(getColumnIndex(_ID))=正确的值

时间:2016-02-19 00:01:15

标签: android sqlite android-sqlite

因此,当我使用int location = cursor.getColumnIndex(_ID)时,它始终返回零,尽管long locationId = cursor.getlong(getColumnIndex(_ID)返回7.为什么我会得到不同的值?

    if (locationCursor.moveToFirst()) {
        //This is where the problem is happening
        locationId = locationCursor.getLong(locationCursor.getColumnIndex(WeatherContract.LocationEntry._ID));
        //=7
        int location = locationCursor.getColumnIndex(WeatherContract.LocationEntry._ID);
        // = 0

1 个答案:

答案 0 :(得分:1)

cursor.getColumnIndex(_ID)返回0,这是数据库表中_ID列的索引(位置)

cursor.getLong(cursor.getColumnIndex(_ID))返回7,这是存储在当前光标所在的数据库表的列_ID中的值。