Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/215.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java Can';t获取电话号码并显示在toast对象上_Java_Android - Fatal编程技术网

Java Can';t获取电话号码并显示在toast对象上

Java Can';t获取电话号码并显示在toast对象上,java,android,Java,Android,我试图在toast对象的联系人列表中显示一个choosen联系人,我想显示姓名和号码,但当我选择联系人时,我的应用程序停止工作,我不知道为什么 这是我的密码: @Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { if (requestCode == REQUEST_SELECT_PHONE_NUMBER && resultCo

我试图在toast对象的联系人列表中显示一个choosen联系人,我想显示姓名和号码,但当我选择联系人时,我的应用程序停止工作,我不知道为什么

这是我的密码:

 @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {

        if (requestCode == REQUEST_SELECT_PHONE_NUMBER && resultCode == RESULT_OK) {
            // Get the URI and query the content provider for the phone number
            Uri contactUri = data.getData();
            String[] projection = new String[]{ContactsContract.CommonDataKinds.Phone.NUMBER};
            Cursor cursor = getContentResolver().query(contactUri, projection,
                    null, null, null);
            // If the cursor returned is valid, get the phone number
            if (cursor != null && cursor.moveToFirst()) {
                int numberIndex = cursor.getColumnIndex(ContactsContract.CommonDataKinds.Phone.NUMBER);
                String number = cursor.getString(numberIndex);
                String contactName = cursor.getString(cursor.getColumnIndex(ContactsContract.Contacts.DISPLAY_NAME));                // Do something with the phone number
                Context context = getApplicationContext();
                CharSequence text = "Hello toast!";
                int duration = Toast.LENGTH_SHORT;
                String fullContact = contactName + ": " + number;

                Toast toast = Toast.makeText(context,fullContact, duration);
                toast.show();
            }
        }
    }
StrackTrace

E/AndroidRuntime: FATAL EXCEPTION: main
                  Process: com.example.filipecosta.mytasks, PID: 3554
                  java.lang.RuntimeException: Failure delivering result ResultInfo{who=null, request=1, result=-1, data=Intent { dat=content://com.android.contacts/contacts/lookup/0r2-2D3F29512F3929/2 flg=0x1 }} to activity {com.example.filipecosta.mytasks/com.example.filipecosta.mytasks.TaskActivity}: java.lang.IllegalArgumentException: Invalid column data1
                      at android.app.ActivityThread.deliverResults(ActivityThread.java:3574)
                      at android.app.ActivityThread.handleSendResult(ActivityThread.java:3617)
                      at android.app.ActivityThread.access$1300(ActivityThread.java:151)
                      at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1352)
                      at android.os.Handler.dispatchMessage(Handler.java:102)
                      at android.os.Looper.loop(Looper.java:135)
                      at android.app.ActivityThread.main(ActivityThread.java:5254)
                      at java.lang.reflect.Method.invoke(Native Method)
                      at java.lang.reflect.Method.invoke(Method.java:372)
                      at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:903)
                      at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698)
                   Caused by: java.lang.IllegalArgumentException: Invalid column data1
                      at android.database.DatabaseUtils.readExceptionFromParcel(DatabaseUtils.java:167)
                      at android.database.DatabaseUtils.readExceptionFromParcel(DatabaseUtils.java:137)
                      at android.content.ContentProviderProxy.query(ContentProviderNative.java:421)
                      at android.content.ContentResolver.query(ContentResolver.java:478)
                      at android.content.ContentResolver.query(ContentResolver.java:422)
                      at com.example.filipecosta.mytasks.TaskActivity.onActivityResult(TaskActivity.java:64)
                      at android.app.Activity.dispatchActivityResult(Activity.java:6192)
                      at android.app.ActivityThread.deliverResults(ActivityThread.java:3570)
                      at android.app.ActivityThread.handleSendResult(ActivityThread.java:3617) 
                      at android.app.ActivityThread.access$1300(ActivityThread.java:151) 
                      at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1352) 
                      at android.os.Handler.dispatchMessage(Handler.java:102) 
                      at android.os.Looper.loop(Looper.java:135) 
                      at android.app.ActivityThread.main(ActivityThread.java:5254) 
                      at java.lang.reflect.Method.invoke(Native Method) 
                      at java.lang.reflect.Method.invoke(Method.java:372) 
                      at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:903) 
                      at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698) 

发布你的stacktrace,这样我们就可以看到错误发生在哪里。更新了问题