Alright I'm back once again trying to get some help with my contacts part of this app I am building. Basically I am trying to select a contact from the in system contact list. This part is done and working just fine. - Where I am having issue is when you pick a name its supposed to set that persons name and phone number into their own respective text views within my app. Logcat is throwing a Null pointer exception supposedly on a specific line of my code. So here is the chunk I am working with:
public void onActivityResult(int reqCode, int resultCode, Intent data) {
super.onActivityResult(reqCode, resultCode, data);
switch (reqCode) {
case (1) :
if (resultCode == Activity.RESULT_OK) {
Uri contactData = data.getData();
Cursor cursor = getContentResolver().query(contactData, null, null, null, null);
cursor.moveToFirst();
String name = cursor.getString(cursor.getColumnIndexOrThrow(ContactsContract.PhoneLookup.DISPLAY_NAME));
//String number = cursor.getString(cursor.getColumnIndexOrThrow(ContactsContract.PhoneLookup.NUMBER));
name1.setText(name);
//num1.setText(number);
}
break;
}
}
Supposedly the issue (NPE) lies on line 103 of my code which is the following:
name1.setText(name);
I commented out the number portion of the code because I figure if I can get this part the next part will fall in line. If anyone see's any issues with that feel free to tell me.
Aside of that - thanks for the help in advance.