Problem about choosing a suspect


#1

Hello, everyone! I met a problem , please help me !
When I click the CHOOSE SUSPECT button, my contact app is opened and the list of contacts is shown. But when I click any person name in the list, it shows a dialog with words : " Unfortunately, CriminalIntent has stoped." Then I click the dialog’s OK button, it brings me back to CrimeFragment which shows a crime’s detail, and the person’s name was not shown on the button.
This problem occurs only when I install CriminalIntent on my cellphone and run it , but it doesn’t occur when I run it in android studio’s AVD . When runing on AVD, after I click a person’s name, that person’s name is correctly shown on the CHOOSE SUSPECT button, and everything is right on the AVD. I am sure the two versions are the same . My cellphone’s OS is android 6.0.


#2

I have a similar issue, when I click on a contact, it brings me back to the crime detail screen, however the person’s name is not displayed on the button. If I click on the Choose Suspect button 2nd time, I get an error " Unfortunately, CriminalIntent has stoped."
Then I click the dialog’s OK button, it brings me back to the contact list. I have double check the code and everything looks identical to the book. What am I missing?


#3

I figured out the issue on my side, I had an extra else if statement before the added code (see the two commented out lines)

if (requestCode == REQUEST_DATE) {
updateDate();
}
//else if (requestCode == REQUEST_TIME) {
// updateTime();
//}
else if (requestCode == REQUEST_CONTACT && data != null) {
Uri contactUri = data.getData();
String queryFields = new String {
ContactsContract.Contacts.DISPLAY_NAME
};
Cursor c = getActivity().getContentResolver().query(contactUri, queryFields, null, null, null);

try {
if (c.getCount() == 0) {
return;
}
c.moveToFirst();
String suspect = c.getString(0);
mCrime.setSuspect(suspect);
mSuspectButton.setText(suspect);
} finally {
c.close();
}
}