android - Contact Picker in PreferenceFragment (failure delivering result error) -
i'm using preferencefragment settings page have 1 preference onclick open contact choose , return result. however, has failure delivering result error.
this preferencefragment class
public class settingsxml extends preferencefragment { private sharedpreferences sharedprefs; final static int pick_contact = 99; @override public void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); // set background drawable addpreferencesfromresource(r.xml.settings); // custom contact pref preference customcontact = (preference)findpreference("prefpick"); customcontact.setonpreferenceclicklistener(new onpreferenceclicklistener() { @override public boolean onpreferenceclick(preference preference) { intent = new intent(intent.action_pick, contactscontract.contacts.content_uri); startactivityforresult(i, pick_contact); return true; } }); } @override public void onactivityresult(int requestcode, int resultcode, intent data) { switch (requestcode) { case pick_contact: if (resultcode == activity.result_ok) { if (data != null) { uri contactdata = data.getdata(); // contactdata returns value log.i(tag, "" + contactdata); string[] projection = {phone.number}; // wrong @ cursor? cursor cursor = ctx.getcontentresolver() .query(contactdata, projection, null, null, null); cursor.movetofirst(); // retrieve phone number number column int column = cursor.getcolumnindex(phone.number); string number = cursor.getstring(column); log.i(tag, "" + number); } } else { // } return; } super.onactivityresult(requestcode, resultcode, data); }
}
and logcat.
05-02 17:36:27.496: w/dalvikvm(6142): threadid=1: thread exiting uncaught exception (group=0xb4e3b908) 05-02 17:36:27.906: d/dalvikvm(6142): gc_concurrent freed 356k, 10% free 4398k/4864k, paused 12ms+64ms, total 146ms 05-02 17:36:30.607: e/androidruntime(6142): fatal exception: main 05-02 17:36:30.607: e/androidruntime(6142): java.lang.runtimeexception: failure delivering result resultinfo{who=android:fragment:0, request=99, result=-1, data=intent { dat=content://com.android.contacts/contacts/lookup/1906i7ef0c7d80ffe6bca/2 flg=0x1 }} activity {settingsfragment}: java.lang.nullpointerexception 05-02 17:36:30.607: e/androidruntime(6142): @ android.app.activitythread.deliverresults(activitythread.java:3319) 05-02 17:36:30.607: e/androidruntime(6142): @ android.app.activitythread.handlesendresult(activitythread.java:3362) 05-02 17:36:30.607: e/androidruntime(6142): @ android.app.activitythread.access$1100(activitythread.java:141) 05-02 17:36:30.607: e/androidruntime(6142): @ android.app.activitythread$h.handlemessage(activitythread.java:1282) 05-02 17:36:30.607: e/androidruntime(6142): @ android.os.handler.dispatchmessage(handler.java:99) 05-02 17:36:30.607: e/androidruntime(6142): @ android.os.looper.loop(looper.java:137) 05-02 17:36:30.607: e/androidruntime(6142): @ android.app.activitythread.main(activitythread.java:5039) 05-02 17:36:30.607: e/androidruntime(6142): @ java.lang.reflect.method.invokenative(native method) 05-02 17:36:30.607: e/androidruntime(6142): @ java.lang.reflect.method.invoke(method.java:511) 05-02 17:36:30.607: e/androidruntime(6142): @ com.android.internal.os.zygoteinit$methodandargscaller.run(zygoteinit.java:793) 05-02 17:36:30.607: e/androidruntime(6142): @ com.android.internal.os.zygoteinit.main(zygoteinit.java:560) 05-02 17:36:30.607: e/androidruntime(6142): @ dalvik.system.nativestart.main(native method) 05-02 17:36:30.607: e/androidruntime(6142): caused by: java.lang.nullpointerexception 05-02 17:36:30.607: e/androidruntime(6142): @ settingsxml.onactivityresult(settingsxml.java:80) 05-02 17:36:30.607: e/androidruntime(6142): @ android.app.activity.dispatchactivityresult(activity.java:5297) 05-02 17:36:30.607: e/androidruntime(6142): @ android.app.activitythread.deliverresults(activitythread.java:3315) 05-02 17:36:30.607: e/androidruntime(6142): ... 11 more
i have permission set @ manifest.
Comments
Post a Comment