Hi everyone
I'm a rookie in Android. I get a problem from Cursor's getInt() function. My code as below:
------------------------------------------------------------------------
ContentResolver resolver = getContentResolver();
Cursor cursor = resolver.query(ContactsContract.CommonDataKinds.Phone.CONTENT_URI, null, null, null, null);
int id = cursor.getInt(cursor.getColumnIndex(ContactsContract.CommonDataKinds.Phone._ID));
------------------------------------------------------------------------
I've traced cursor.getColumnIndex(ContactsContract.CommonDataKinds.Phone._ID) and it should return value 56 while it find "_id" string. And I also trace cursor.getInt() and find it just return an integer value. So, I think this code will work but it crushed. After I removed cursor.getInt() function to be "int id = cursor.getColumnIndex(ContactsContract.CommonDataKinds.Phone._ID);".
It became to work and id get 56 value properly.
Does anyone know the reason about it?
Thank you so much!
I'm a rookie in Android. I get a problem from Cursor's getInt() function. My code as below:
------------------------------------------------------------------------
ContentResolver resolver = getContentResolver();
Cursor cursor = resolver.query(ContactsContract.CommonDataKinds.Phone.CONTENT_URI, null, null, null, null);
int id = cursor.getInt(cursor.getColumnIndex(ContactsContract.CommonDataKinds.Phone._ID));
------------------------------------------------------------------------
I've traced cursor.getColumnIndex(ContactsContract.CommonDataKinds.Phone._ID) and it should return value 56 while it find "_id" string. And I also trace cursor.getInt() and find it just return an integer value. So, I think this code will work but it crushed. After I removed cursor.getInt() function to be "int id = cursor.getColumnIndex(ContactsContract.CommonDataKinds.Phone._ID);".
It became to work and id get 56 value properly.
Does anyone know the reason about it?
Thank you so much!