Null pointer exception



When my crime list fragment starts a crime fragment then the id that is retrieved through the extra is not the same as in crime list fragment. This produces a null pointer exception. Also, in the crimelab, I have a log in the if condition but that never gets logged meaning the if condition never gets true. Can somebody pleas help me with this.

public class CrimeListFragment extends ListFragment { .. @Override public void onListItemClick(ListView l, View v, int position, long id) { Crime c= ((CrimeAdapter)getListAdapter()).getItem(position); Intent i = new Intent(getActivity(), CrimeActivity.class); Log.d(TAG, c.getmTitle() + " " + c.getmId()); i.putExtra(CrimeFragment.EXTRA_CRIME_ID, c.getmId()); startActivity(i); } .. }

public class CrimeFragment extends Fragment {
	public void onCreate(Bundle savedInstanceState) {
		UUID crimeId = (UUID)getActivity().getIntent().getSerializableExtra(EXTRA_CRIME_ID);
                //mCrime = new Crime();
		Log.d(TAG, CrimeLab.get(getActivity()).getCrime(crimeId).getmTitle());
		df = DateFormat.getDateInstance();

[code]public class CrimeLab {

public Crime getCrime(UUID id){
for (Crime c:mCrimes){
if (c.getmId() == id)
Log.d(TAG, c.getmTitle());
return c;
return null;




One problem is in CrimeLab.getCrime(UUID) you need to use ‘.equals’ instead of ‘==’. I don’t know if there are other problems.