shotgunsam shotgunsam - 6 months ago 34
Android Question

getColumnIndex(_ID) returns zero, getlong(getColumnIndex(_ID)) = correct value

So when I use the

int location = cursor.getColumnIndex(_ID)
it always returns zero, despite
long locationId = cursor.getlong(getColumnIndex(_ID)
returns 7. Why is it that I'm getting different values?

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


cursor.getColumnIndex(_ID) returns 0 which is the index (position) of the _ID column in the database table

cursor.getLong(cursor.getColumnIndex(_ID)) returns 7 which is the value stored in the column _ID of the database table where the cursor is positioned (row) currently.