因此,当我使用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
答案 0 :(得分:1)
cursor.getColumnIndex(_ID)
返回0
,这是数据库表中_ID
列的索引(位置)
cursor.getLong(cursor.getColumnIndex(_ID))
返回7
,这是存储在当前光标所在的数据库表的列_ID
中的值。