Problem with starting the crime activity in the criminalintent app from android programming the big nerd ranch guide


so everything worked great with the criminalintent app up until page 209. "the problem with direct retrieval." i have previous experience with java but i am completely new to android programming and i am pretty much just trying to follow the directions exactly. i have gone over my code again and again but i do not understand the problem and as far as i can see my code matches the code in the book exactly. when the application is launched it runs at first but since switching from direct retrieval to using fragment arguments any click causes the entire application to crash. like i said before switching to fragment arguments clicking a list item succesfully launched the crimeActivity. i will include some of the code here. please let me know if you can find any thing wrong. thanks!

public class CrimeListFragment extends Fragment{ private RecyclerView mCrimeRecyclerView; private CrimeAdapter mAdapter;

public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState){
    View view = inflater.inflate(R.layout.fragment_crime_list, container, false);

    mCrimeRecyclerView = (RecyclerView) view.findViewById(;
    mCrimeRecyclerView.setLayoutManager(new LinearLayoutManager(getActivity()));


    return view;
}//end onCreate

public void onResume(){

private void updateUI(){
    CrimeLab crimeLab = CrimeLab.get(getActivity());
    List<Crime> crimes = crimeLab.getCrimes();

        if (mAdapter == null){
        mAdapter = new CrimeAdapter(crimes);
        }else {

}//end updateUI()

private class CrimeHolder extends RecyclerView.ViewHolder implements View.OnClickListener{
    private TextView mTitleTextView;
    private TextView mDateTextView;
    private Crime mCrime;
    private ImageView mSolvedImageView;

    public CrimeHolder(LayoutInflater inflater, ViewGroup parent){
        super(inflater.inflate(R.layout.list_item_crime, parent, false));

        mTitleTextView = (TextView) itemView.findViewById(;
        mDateTextView = (TextView) itemView.findViewById(;
        mSolvedImageView = (ImageView) itemView.findViewById(;
    }//end constructor

    public void onClick(View view){
        Intent intent = CrimeActivity.newIntent(getActivity(), mCrime.getId());
    }//end onCLick()

    public void bind(Crime crime){
        mCrime = crime;
        mSolvedImageView.setVisibility(crime.isSolved() ? View.VISIBLE : View.GONE);
    }//end bind()

}//end CrimeHolder inner Class

private class CrimeAdapter extends RecyclerView.Adapter<CrimeHolder>{

    private List<Crime> mCrimes;

    public CrimeAdapter(List<Crime> crimes){
        mCrimes = crimes;
    }//end constructor
    public CrimeHolder onCreateViewHolder(ViewGroup parent, int viewType){
        LayoutInflater layoutInflater = LayoutInflater.from(getActivity());

        return new CrimeHolder(layoutInflater, parent);

    }// end onCreateViewHolder

    public void onBindViewHolder(CrimeHolder holder, int position){
        Crime crime = mCrimes.get(position);

    public int getItemCount(){
        return mCrimes.size();

}//end CrimeAdapter inner Class

}//end CrimeListFragment class

public class CrimeActivity extends SingleFragmentActivity {

private static final String EXTRA_CRIME_ID = "";

public static Intent newIntent(Context packageContext, UUID crimeId){
    Intent intent = new Intent(packageContext, CrimeActivity.class);
    intent.putExtra(EXTRA_CRIME_ID, crimeId);
    return intent;

protected Fragment createFragment(){
    UUID crimeId = (UUID) getIntent().getSerializableExtra(EXTRA_CRIME_ID);
    return CrimeFragment.newInstance(crimeId);

}//end crime activity

public class CrimeFragment extends Fragment{

public static final String ARG_CRIME_ID = "crime_id";

private Crime mCrime;
private EditText mTitleField;
private Button mDateButton;
private CheckBox mSolvedCheckBox;

public static CrimeFragment newInstance(UUID crimeId){
    Bundle args = new Bundle();
    args.putSerializable(ARG_CRIME_ID, crimeId);

    CrimeFragment fragment = new CrimeFragment();
    return fragment;

public void onCreate(Bundle savedInstanceState){

    UUID crimeId = (UUID) getArguments().getSerializable(ARG_CRIME_ID);
    mCrime = CrimeLab.get(getActivity()).getCrime(crimeId);

}//end onCreate()

public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState){
    View v = inflater.inflate(R.layout.fragment_crime, container, false);

    mTitleField = (EditText) v.findViewById(;
    mTitleField.addTextChangedListener(new TextWatcher() {
        public void beforeTextChanged(CharSequence s, int start, int count, int after) {


        public void onTextChanged(CharSequence s, int start, int before, int count) {

        public void afterTextChanged(Editable s) {

    });//end textChangedListener

    mSolvedCheckBox = (CheckBox) v.findViewById(;
    mSolvedCheckBox.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
        public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
    });//end checkedchangedlistener

    mDateButton = (Button) v.findViewById(;

    return v;
}//end onCreateView()

}//end class


I had a similar problem.

Make sure .CrimeActivity is included in your AndroidManifest.xml file:

<activity android:name=".CrimeActivity">