Try to simplify bindCrime function in CrimeHolder class ... doesn't work

#1

Hello,

I’ve tried to simplify bindCrime function:

  public void bindCrime(Crime crime) {
     mTitleTextView.setText(crime.getTitle());
     mDateTextView.setText(crime.getDate().toString());
     mSolvedCheckBox.setChecked(crime.isSolved());
  }

instead of

  public void bindCrime(Crime crime) {
     mCrime = crime;
     mTitleTextView.setText(mCrime.getTitle());
     mDateTextView.setText(mCrime.getDate().toString());
     mSolvedCheckBox.setChecked(mCrime.isSolved());
  }

It doesn’t work - application crashes on launching.
The member mCrime is used only inside bindCrime … or I missed something ?

Thanks

#2
  1. What’s your crash log?
  2. Does it work when using mCrime = crime?
  3. Do you have the following code which uses mCrime? However, you said crash occurred on launching. With the following code, crash will only occur when clicking the button.
        public CrimeHolder(View itemView) {
            super(itemView);

            itemView.setOnClickListener(new View.OnClickListener() {
                @Override
                    public void onClick(View v) {
                        Toast.makeText(getActivity(), mCrime.getTitle() + " clicked!",
                                 Toast.LENGTH_LONG).show();
                    }
                });

                ......
            }