我使用此代碼打開我的聯繫人列表,然後選擇一個聯繫人以顯示在我的用戶界面中。我可以打開我的聯繫人列表,但是當我點擊任何聯繫人時,程序崩潰。打開手機聯繫人列表,然後選擇一個聯繫人
etphone1.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
// Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
// intent.setType(ContactsContract.CommonDataKinds.Phone.CONTENT_ITEM_TYPE);
// startActivityForResult(intent, 1);
Intent pb = new Intent(Intent.ACTION_PICK,
ContactsContract.Contacts.CONTENT_URI);
startActivityForResult(pb, 1);
}
});
我onActivityForResult
:
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
// TODO Auto-generated method stub
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == 1) {
if (resultCode == RESULT_OK) {
Uri contactData = data.getData();
Cursor cursor = managedQuery(contactData, null, null, null,
null);
cursor.moveToFirst();
String number = cursor
.getString(cursor
.getColumnIndexOrThrow(ContactsContract.CommonDataKinds.Phone.NUMBER));
TextView tv;
tv = (TextView) findViewById(R.id.tv);
tv.setText(number);
}
}
}
的logcat:
12-11 11:05:48.969: E/AndroidRuntime(16292): java.lang.RuntimeException: Failure delivering result ResultInfo{who=null, request=1, result=-1, data=Intent { dat=content://com.android.contacts/contacts/lookup/0r10-272B2B434F414D37413143/10 flg=0x1 }} to activity {com.sriyank.locationmessenger/com.sriyank.locationmessenger.SecondPage}: java.lang.IllegalArgumentException: column 'data1' does not exist
12-11 11:05:48.969: E/AndroidRuntime(16292): at android.app.ActivityThread.deliverResults(ActivityThread.java:3209)
12-11 11:05:48.969: E/AndroidRuntime(16292): at android.app.ActivityThread.handleSendResult(ActivityThread.java:3252)
12-11 11:05:48.969: E/AndroidRuntime(16292): at android.app.ActivityThread.access$1200(ActivityThread.java:143)
12-11 11:05:48.969: E/AndroidRuntime(16292): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1289)
12-11 11:05:48.969: E/AndroidRuntime(16292): at android.os.Handler.dispatchMessage(Handler.java:99)
12-11 11:05:48.969: E/AndroidRuntime(16292): at android.os.Looper.loop(Looper.java:137)
12-11 11:05:48.969: E/AndroidRuntime(16292): at android.app.ActivityThread.main(ActivityThread.java:4960)
12-11 11:05:48.969: E/AndroidRuntime(16292): at java.lang.reflect.Method.invokeNative(Native Method)
12-11 11:05:48.969: E/AndroidRuntime(16292): at java.lang.reflect.Method.invoke(Method.java:511)
12-11 11:05:48.969: E/AndroidRuntime(16292): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1038)
12-11 11:05:48.969: E/AndroidRuntime(16292): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:805)
12-11 11:05:48.969: E/AndroidRuntime(16292): at dalvik.system.NativeStart.main(Native Method)
12-11 11:05:48.969: E/AndroidRuntime(16292): Caused by: java.lang.IllegalArgumentException: column 'data1' does not exist
12-11 11:05:48.969: E/AndroidRuntime(16292): at android.database.AbstractCursor.getColumnIndexOrThrow(AbstractCursor.java:302)
12-11 11:05:48.969: E/AndroidRuntime(16292): at android.database.CursorWrapper.getColumnIndexOrThrow(CursorWrapper.java:78)
12-11 11:05:48.969: E/AndroidRuntime(16292): at com.sriyank.locationmessenger.SecondPage.onActivityResult(SecondPage.java:59)
哪裏是你的logcat的錯誤? – GrIsHu
很難找到這個唯一的單詞'Crashing'的問題。請張貼您的日誌貓? –
這裏是我的日誌貓: – user3080161