Issue with Listing 9.6


#1

Hi,

I went through chapter 9 without much trouble, then I got through most of chapter 10 and was having trouble get the title to display when I clicked a crime. I went back through the code to see if I made a mistake.

I found a typo on line
mCrimes = CrimeLab.get(getActivity()).getCrimes(); (listing 9.6)

I had
mCrimes = CrimeLab.get(getActivity()).getmCrimes();

when I corrected

.getmCrimes to .getCrimes

I get an error that says "cannot resolve method getCrimes();

I am not sure what I have done wrong. Any help would be great.

Thanks.

[code]
public class CrimeListFragment extends ListFragment {
// private static final String TAG = “CrimeListFragment”;
private ArrayList mCrimes;

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    getActivity().setTitle(R.string.crimes_title);
    mCrimes = CrimeLab.get(getActivity()).getCrimes();

    CrimeAdapter adapter = new CrimeAdapter(mCrimes);
    setListAdapter(adapter);
}

@Override
public  void onListItemClick(ListView l, View v, int position, long id) {
    Crime c = ((CrimeAdapter)getListAdapter()).getItem(position);

    //start crime activity
    Intent i = new Intent(getActivity(), CrimeActivity.class);
    i.putExtra(CrimeFragment.EXTRA_CRIME_ID, c.getId());
    startActivity(i);
}

private class CrimeAdapter extends ArrayAdapter<Crime> {
    public CrimeAdapter(ArrayList<Crime> crimes) {
        super(getActivity(), 0, crimes);
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        //if we weren't given a view inflate one
        if (convertView == null) {
           convertView = getActivity().getLayoutInflater() .inflate(R.layout.list_item_crime, null);
        }

        //configure the view for this crime
        Crime c = getItem(position);

        TextView titleTextView = (TextView)convertView.findViewById(R.id.crime_list_item_titleTextView);
        titleTextView.setText(c.getTitle());
        TextView dateTextView = (TextView)convertView.findViewById(R.id.crime_list_item_dateTextView);
        dateTextView.setText(c.getDate().toString());
        CheckBox solvedCheckBox = (CheckBox)convertView.findViewById(R.id.crime_list_item_solvedCheckBox);
        solvedCheckBox.setChecked(c.isSolved());

        return convertView;
    }
}

}[/code]


#2

What do you have in CrimeLab.java ?

It should have among other things

public ArrayList<Crime> getCrimes() {
		return mCrimes;
}