首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >失败传递结果ResultInfo{who=null,request=1,结果=-1,data=Intent {who=null}}

失败传递结果ResultInfo{who=null,request=1,结果=-1,data=Intent {who=null}}
EN

Stack Overflow用户
提问于 2014-12-08 11:34:26
回答 1查看 4K关注 0票数 0

从联系人列表中选择联系人时出错。你的任何帮助都会很好..。下面是从contact接收号码并在编辑文本视图中显示的代码:

私有空importContact() {

代码语言:javascript
复制
    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();
                }
            }
        }

下面是日志猫错误:

代码语言:javascript
复制
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
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2014-12-08 13:32:45

您必须首先像这样查询联系人DB:

代码语言:javascript
复制
ContentResolver resolvr = getContentResolver();  
Cursor cursor = resolvr.query(ContactsContract.Contacts.CONTENT_URI, null, null, null, null);

resultSet在cursor

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/27357111

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档