![](/img/trans.png)
[英]Failure delivering result ResultInfo{who=null, request=1, result=-1, data=Intent { dat=content://com.android.contacts/contacts/lookup...}}
[英]Failure delivering result ResultInfo{who=null, request=1, result=-1, data=Intent { dat=content://com.android.contacts/contacts/lookup…}}
從聯系人列表中選擇聯系人時出錯。 您的任何幫助都將非常好...這是從聯系人接收號碼並將其顯示在編輯文本視圖中的代碼:
私人無效importContact(){
Intent importContactIntent = new Intent(Intent.ACTION_PICK);
importContactIntent.setType(ContactsContract.Contacts.CONTENT_TYPE);
startActivityForResult(importContactIntent, PICK_CONTACT);
}
@Override
public void onActivityResult(int reqCode, int resultCode, Intent data) {
super.onActivityResult(reqCode, resultCode, data);
switch (reqCode) {
case (PICK_CONTACT):
if (resultCode == Activity.RESULT_OK) {
// Uri contactData = data.getData();
String id = cursor.getString(cursor
.getColumnIndex(ContactsContract.Contacts._ID));
String name = cursor
.getString(cursor
.getColumnIndex(ContactsContract.Contacts.DISPLAY_NAME));
if (Integer
.parseInt(cursor.getString(cursor
.getColumnIndex(ContactsContract.Contacts.HAS_PHONE_NUMBER))) > 0) {
// System.out.println("name : " + name + ", ID : " + id);
// NOW query all numbers of that particulat contact using
// contact_Id
Cursor pCur = getContentResolver().query(
ContactsContract.CommonDataKinds.Phone.CONTENT_URI,
null,
ContactsContract.CommonDataKinds.Phone.CONTACT_ID
+ " = ?", new String[] { id }, null);
while (pCur.moveToNext()) {
// you can store phone in a arrayList
destinationPhoneNumber = pCur
.getString(pCur
.getColumnIndex(ContactsContract.CommonDataKinds.Phone.NUMBER));
//
enterPhoneNumber.setText(destinationPhoneNumber);
Toast.makeText(this,
name + " has number " + destinationPhoneNumber,
Toast.LENGTH_LONG).show();
cursor.close();
}
}
}
這是日志貓錯誤:
FATAL EXCEPTION: main
java.lang.RuntimeException: Failure delivering result ResultInfo{who=null, request=1, result=-1, data=Intent { dat=content://com.android.contacts/contacts/lookup/0i473.3217i217333/217328 (has extras) }} to activity {np.com.rsubedi.balancetransfer/np.com.rsubedi.balancetransfer.BTmain}: java.lang.NullPointerException
at android.app.ActivityThread.deliverResults(ActivityThread.java:3515)
at android.app.ActivityThread.handleSendResult(ActivityThread.java:3557)
at android.app.ActivityThread.access$2800(ActivityThread.java:125)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2063)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:123)
at android.app.ActivityThread.main(ActivityThread.java:4627)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:521)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:858)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.NullPointerException
at np.com.rsubedi.balancetransfer.BTmain.onActivityResult(BTmain.java:220)
at android.app.Activity.dispatchActivityResult(Activity.java:3890)
at android.app.ActivityThread.deliverResults(ActivityThread.java:3511)
... 11 more
您必須首先查詢Contacts數據庫,如下所示:
ContentResolver resolvr = getContentResolver();
Cursor cursor = resolvr.query(ContactsContract.Contacts.CONTENT_URI, null, null, null, null);
resultSet在cursor
。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.