Can't compile CrimeListFragment.java

#1

After created “fragment_crime.xml” successfully and when try to fill CrimeListFragment, “the R.id.crime_recycler_view” is not found, only crime_solved, crime_title and crime_date are found. I rechecked several times the code, but it’s the same as the book. What could be the error?

Best regards,

#2

Error found!!
there was a space between < and android.support… in fragment_crime_list.xml. After run grade sync, I found it.

#3

I am using the below code:
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.getmTitle());
TextView dateTextView =
(TextView)convertView.findViewById(R.id.crime_list_item_dateTextView);
dateTextView.setText(c.getmDate().toString());
CheckBox solvedCheckBox =
(CheckBox)convertView.findViewById(R.id.crime_list_item_solvedCheckBox);
solvedCheckBox.setChecked(c.ismSolved());
return convertView;
}

It gives error in Crime c = getItem(position); line.
The error is: Cannot reslove method getItem(int).

Please help me out.

#4

public class CrimeListFragment extends Fragment {
private RecyclerView mCrimeRecyclerView;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.fragment_crime_list, container, false);
mCrimeRecyclerView = (RecyclerView) view
.findViewById(R.id.crime_recycler_view);
mCrimeRecyclerView.setLayoutManager(new LinearLayoutManager(getActivity()));
return view;
}
}

–Note that as soon as you create your RecyclerView, you give it another object called a LayoutManager.
RecyclerView requires a LayoutManager to work. If you forget to give it one, it will crash.

I got stuck here please help me out.If i compile this one it will get crashed.The bold one which i cant understand can you please help me