我正在使用意图检索电话号码。它正在显示联系人列表。现在我想找一个联系人。但是当我点击任何一个联系人时,出现异常。它发生在号码检索期间,但对于联系人姓名检索是正确的。
Intent intent = new Intent(Intent.ACTION_PICK);
intent.setType(ContactsContract.Contacts.CONTENT_TYPE);
startActivityForResult(intent, 2);
Uri contactUri = data.getData();
//String[] projection = {Phone.NUMBER};
Cursor cursor = getContentResolver()
.query(contactUri, null, null, null, null);
cursor.moveToNext();
// String name = cursor.getString(cursor.getColumnIndex(ContactsContract.CommonDataKinds.Phone.DISPLAY_NAME));// name got me.
String phone = cursor.getString(cursor.getColumnIndex(ContactsContract.CommonDataKinds.Phone.NUMBER)); // exception for phone number.
System.out.println("name "+name+phone);
日志猫:-
06-21 18:06:38.394: E/AndroidRuntime(30700): java.lang.RuntimeException: Failure delivering result ResultInfo{who=null, request=2, result=-1, data=Intent { dat=content://com.android.contacts/contacts/lookup/1135r4-2727494D372D37.3754r14-2727494D372D37/4 }} to activity {com.MednymaSecureChat/com.MednymaSecureChat.XMPPClient}: java.lang.IllegalStateException: Couldn't read row 0, col -1 from CursorWindow. Make sure the Cursor is initialized correctly before accessing data from it.
06-21 18:06:38.394: E/AndroidRuntime(30700): at android.app.ActivityThread.deliverResults(ActivityThread.java:2980)
06-21 18:06:38.394: E/AndroidRuntime(30700): at android.app.ActivityThread.handleSendResult(ActivityThread.java:3023)
06-21 18:06:38.394: E/AndroidRuntime(30700): at android.app.ActivityThread.access$1100(ActivityThread.java:123)
06-21 18:06:38.394: E/AndroidRuntime(30700): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1177)
06-21 18:06:38.394: E/AndroidRuntime(30700): at android.os.Handler.dispatchMessage(Handler.java:99)
06-21 18:06:38.394: E/AndroidRuntime(30700): at android.os.Looper.loop(Looper.java:137)
06-21 18:06:38.394: E/AndroidRuntime(30700): at android.app.ActivityThread.main(ActivityThread.java:4424)
06-21 18:06:38.394: E/AndroidRuntime(30700): at java.lang.reflect.Method.invokeNative(Native Method)
06-21 18:06:38.394: E/AndroidRuntime(30700): at java.lang.reflect.Method.invoke(Method.java:511)
06-21 18:06:38.394: E/AndroidRuntime(30700): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:817)
06-21 18:06:38.394: E/AndroidRuntime(30700): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:584)
06-21 18:06:38.394: E/AndroidRuntime(30700): at dalvik.system.NativeStart.main(Native Method)
06-21 18:06:38.394: E/AndroidRuntime(30700): Caused by: java.lang.IllegalStateException: Couldn't read row 0, col -1 from CursorWindow. Make sure the Cursor is initialized correctly before accessing data from it.
06-21 18:06:38.394: E/AndroidRuntime(30700): at android.database.CursorWindow.nativeGetString(Native Method)
06-21 18:06:38.394: E/AndroidRuntime(30700): at android.database.CursorWindow.getString(CursorWindow.java:442)
06-21 18:06:38.394: E/AndroidRuntime(30700): at android.database.AbstractWindowedCursor.getString(AbstractWindowedCursor.java:51)
06-21 18:06:38.394: E/AndroidRuntime(30700): at android.database.CursorWrapper.getString(CursorWrapper.java:114)
06-21 18:06:38.394: E/AndroidRuntime(30700): at com.MednymaSecureChat.XMPPClient.onActivityResult(XMPPClient.java:480)
06-21 18:06:38.394: E/AndroidRuntime(30700): at android.app.Activity.dispatchActivityResult(Activity.java:4654)
06-21 18:06:38.394: E/AndroidRuntime(30700): at android.app.ActivityThread.deliverResults(ActivityThread.java:2976)
06-21 18:06:38.394: E/AndroidRuntime(30700): ... 11 more
请任何人帮助我