Issues with 9.19


#1

I’m having a couple of error in 9.19. Everything has worked up to this point. I’ve double checked all my work.

@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);
}

The method getView(int, View, ViewGroup) of type CrimeListFragment must override or implement a supertype method

and

Crime c = getItem(position);

The method getItem(int) is undefined for the type CrimeListFragment

I don’t know enough to figure this out. What am I doing wrong. Can you please help? Thanks


#2

I happen to have exactly the same problem. Please let me know if you found the answer to this issue. On Android-Studio the error message is "Cannot resolve Method ‘getItem(Int)’

Thanks


#3

Just in case it makes any difference I’m using the new Android Studio IDE.


#4

The problem was with my code. I got the download from the book code and checked it against mine. Issue was solved.


#5

What exactly was different in the code?


#6

I had the same problem. I had a misplaced bracket in the inner class. My code looked like this:

private class CrimeAdapter extends ArrayAdapter<Crime> { public CrimeAdapter(ArrayList<Crime> crimes) { super(getActivity(), android.R.layout.simple_list_item_1, crimes); } } //This brace in the wrong place. Should be at end after return statement ...

However the bracket should have been at the end of the code after:

return convertView;