Я пытаюсь получить информацию о выбранном контакте, но, к сожалению, я получаю исключение gettin Caused by: java.lang.IllegalArgumentException: Invalid column data1
Я скопировал код из руководства по эксплуатации Android. Вот мой код. Я делаю это из фрагмента в активности по методу результата. Данные не являются нулевыми, они вызывают исключение в методе запроса.Попытка получить контактную информацию Недействительный столбец данных
case REQUEST_CODE_CONTACT:
// Get the URI that points to the selected contact
Uri contactUri = data.getData();
// We only need the NUMBER column, because there will be only one row in the result
String[] projection = {ContactsContract.CommonDataKinds.Phone.NUMBER, ContactsContract.CommonDataKinds.Phone.DISPLAY_NAME};
// Perform the query on the contact to get the NUMBER column
// We don't need a selection or sort order (there's only one result for the given URI)
// CAUTION: The query() method should be called from a separate thread to avoid blocking
// your app's UI thread. (For simplicity of the sample, this code doesn't do that.)
// Consider using CursorLoader to perform the query.
Cursor cursor = getActivity().getApplicationContext().getContentResolver().query(contactUri, projection, null, null, null);
cursor.moveToFirst();
// Retrieve the phone number from the NUMBER column
int columnNumber = cursor.getColumnIndex(ContactsContract.CommonDataKinds.Phone.NUMBER);
int columnName = cursor.getColumnIndex(ContactsContract.CommonDataKinds.Phone.DISPLAY_NAME);
String number = cursor.getString(columnNumber);
String name = cursor.getString(columnName);
Toast.makeText(getActivity().getApplicationContext(),"You have selected "+name + " " + number,Toast.LENGTH_LONG).show();
Сообщение об исключении кажется вполне понятным. – corsair992
Вы можете сделать свое исключение Google ('IllegalArgumentException: Invalid column data1'), вы получите много сообщений об этом. –
А также публикация полной трассировки стека может помочь найти причину/местоположение исключения. –