0

in my app I need to point the user to the contact list, and then receive a selection. I found a very descriptive tutorial, but I keep getting an uncaught exception.

 protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        if (resultCode == RESULT_OK) {
            switch (requestCode) {
            case CONTACT_PICKER_RESULT:
                 Bundle extras = data.getExtras();
    Set<String> keys = extras.keySet(); //NullPointerException on this line

    Iterator<String> iterate = keys.iterator();
    while (iterate.hasNext()) {
        String key = iterate.next();
        Log.v(DEBUG_TAG, key + "[" + extras.get(key) + "]");
    }
    Uri result = data.getData();
    Log.v(DEBUG_TAG, "Got a result: "
        + result.toString());
                break;
            }

        } 
    }

EDIT: Here is the Runtime Exception that is caused by the NullPointerException shown before.

java.lang.RuntimeException: Failure delivering result ResultInfo{who=null, request=1001, result=-1, data=Intent { dat=content://com.android.contacts/contacts/lookup/0n293F45435B45/1 }} to activity {com.ptylabs.loveyousms/com.myapps.myApp.MyActivity}: java.lang.NullPointerException

And yes, I have the permissions set.

Any ideas whats going on? Thanks!

Community
  • 1
  • 1
leonsas
  • 4,718
  • 6
  • 43
  • 70
  • I couldn't find what was wrong. So I changed my code to something like http://stackoverflow.com/questions/5112392/getting-contact-phone-number – leonsas Aug 24 '11 at 03:34

1 Answers1

0

It's always better if you show us the exception. What I usually do is, on the OnClickListener of the button assigned to go to the Pick Contact Activity I do the following:

startActivityForResult(new Intent(Intent.ACTION_PICK, Contacts.CONTENT_URI), CONTACT_PICKER_RESULT);

Also, do not forget this in the manifest file:

<uses-permission android:name="android.permission.READ_CONTACTS" />

Your code is working fine here with these two things.

08-24 03:24:48.115: VERBOSE/debug(12600): android.intent.extra.shortcut.NAME[xxxx@hotmail.com] 08-24 03:24:48.115: VERBOSE/debug(12600): Got a result: content://com.android.contacts/contacts/lookup/45id8ae8460ccfefc0/37

Edgar
  • 2,500
  • 19
  • 31