Am able to setup a different view for the RecyclerView to show a contact police button when is selected in the crime object.
However, I am at a loss how to wire this button up? I get a Null Pointer exception when I try to either set this in the constructor of the ViewHolder, or in the bind method…
java.lang.NullPointerException: Attempt to invoke virtual method 'void android.widget.Button.setOnClickListener(android.view.View$OnClickListener)' on a null object reference
Here is the code as implemented in my bind method.
public void bind (Crime crime) {
mCrime = crime;
mTitleTextView.setText(mCrime.getTitle());
mDateTextView.setText(mCrime.getDate().toString());
if (mCrime.isPoliceRequired()) {
mContactPoliceButton.setOnClickListener(new View.OnClickListener(){
@Override
public void onClick(View v) {
Toast.makeText(getActivity(), "Police Contacted", Toast.LENGTH_SHORT).show();
}
});
}
}
any help is welcome!