Null pointer exception


#1

Hi,

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 {
..
	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(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;

}


}
[/code]


#2

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