Android 接受来自联系人的活动结果的非法辩论?
我使用此方法返回结果代码,然后从contacts数据库中获取联系人信息Android 接受来自联系人的活动结果的非法辩论?,android,android-contacts,Android,Android Contacts,我使用此方法返回结果代码,然后从contacts数据库中获取联系人信息 protected void onActivityResult(int requestCode, int resultCode, Intent data) { switch (requestCode) { case (CONTACT_PICKER_RESULT) : if (resultCode == Activity.RESULT_OK) { Ur
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
switch (requestCode) {
case (CONTACT_PICKER_RESULT) :
if (resultCode == Activity.RESULT_OK) {
Uri contactData = data.getData();
Cursor cursor = managedQuery(contactData, null, null, null, null);
while (cursor.moveToNext())
{
String contactId = cursor.getString(cursor.getColumnIndex(ContactsContract.Contacts._ID));
name = cursor.getString(cursor.getColumnIndexOrThrow(ContactsContract.Contacts.DISPLAY_NAME));
String hasPhone = cursor.getString(cursor.getColumnIndex(ContactsContract.Contacts.HAS_PHONE_NUMBER));
if ( hasPhone.equalsIgnoreCase("1"))
hasPhone = "true";
else
hasPhone = "false" ;
if (Boolean.parseBoolean(hasPhone))
{
Cursor phones = getContentResolver().query(ContactsContract.CommonDataKinds.Phone.CONTENT_URI, null,ContactsContract.CommonDataKinds.Phone.CONTACT_ID +" = "+ contactId,null, null);
while (phones.moveToNext())
{
phoneNumber = phones.getString(phones.getColumnIndex(ContactsContract.CommonDataKinds.Phone.NUMBER));
}
phones.close();
}
break;
}
ContactInfo.setText("Contact: " + name + "./n" + " Phone Number: "+ phoneNumber);
}
}
}
问题是我一直在犯这个错误
10-13 17:27:19.017: ERROR/AndroidRuntime(6781): java.lang.RuntimeException: Failure delivering result ResultInfo{who=null, request=1001, result=-1, data=Intent { dat=content://com.android.contacts/data/229 flg=0x1 (has extras) }} to activity {com.fttech.test2/com.fttech.test2.TestContacts}: java.lang.IllegalStateException: get field slot from row 0 col -1 failed
10-13 17:27:19.017: ERROR/AndroidRuntime(6781): Caused by: java.lang.IllegalStateException: get field slot from row 0 col -1 failed
10-13 17:27:19.017: ERROR/AndroidRuntime(6781): at android.database.CursorWindow.getString_native(Native Method)
10-13 17:27:19.017: ERROR/AndroidRuntime(6781): at android.database.CursorWindow.getString(CursorWindow.java:375)
10-13 17:27:19.017: ERROR/AndroidRuntime(6781): at android.database.AbstractWindowedCursor.getString(AbstractWindowedCursor.java:49)
10-13 17:27:19.017: ERROR/AndroidRuntime(6781): at android.database.CursorWrapper.getString(CursorWrapper.java:135)
我认为您的问题在于一些
游标.getColumnIndex
,可能是联系人contract.Contacts.\u ID
是问题所在。
但是我给你的建议是,一个一个地调试,在所有的联系人上放置一个手表contract.
access
返回a-1的人就是给你带来问题的人