Thursday, November 4, 2010

Java.lang.IllegalArgumentException: column '_id' does not exist

Its a common error when we use a data adapter in ANDROID for the first time. I used it to extract all the contacts.

So we declare a SimpleCursorAdapter as follows



SimpleCursorAdapter adapter = new SimpleCursorAdapter(
this,
R.layout.contactsview,
c,
projection,
new int[] {R.id.contactEntryText}
);




I used the projections as follows


String [] projection = new String [] {
ContactsContract.Contacts.DISPLAY_NAME
};


I got the exception Java.lang.IllegalArgumentException: column '_id' does not exist.

Make sure that the projection you have mentioned above do contain a field called as ContactsContract.Contacts._ID.

So you have to redeclare the array projection as




String [] projection = new String [] {
ContactsContract.Contacts.DISPLAY_NAME,
ContactsContract.Contacts._ID
};



Thats it. Now you are good to go !!!!!!!!

No comments:

Post a Comment