Listing 10.8, 'method does not override' error


#1

When I follow listing 10.8 and override ‘onResume()’ in CrimeListFragment I’m told that the method does not override or implement a method from a supertype.

Ca nsomeone please help me figure this out?


#2

One possibility is the JDK version you have Eclipse set to use. Seems this may happen if set to 1.5 rather than 1.6. Have a look at this Stackoverflow question and see if it pertains to your case: http://stackoverflow.com/questions/1678122/must-override-a-superclass-method-errors-after-importing-a-project-into-eclips


#3

No, this is not the case. 1) I’m not using Eclipse, 2) I only have one JDK installed and it’s 1.8.


#4

OK, if you’re sure the signature of the overridden method exactly matches that of the parent class, then I guess I’m fresh out of ideas of what the problem might be.


#5

Here’s my code for CrimeListFragment.java as of the listing for 10.8. Note the bit for onResume(), which is the part with the error.

[code]package criminalintent.android.bignerdranch.com.criminalintent;

import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.ListFragment;
import android.util.Log;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.CheckBox;
import android.widget.ListView;
import android.widget.TextView;
import java.util.ArrayList;

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 onRusume() {
    super.onResume();
    ((CrimeAdapter)getListAdapter()).notifyDataSetChanged();
}

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

    //Start CrimeActivity
    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]


#6

If this is the exact code with the error, then take a close look at how your spelled the method name. The compiler is usually always correct  :wink:

If this is the exact code with the error, then take a close look at how your spelled the method name. The compiler is usually always correct :wink:


#7

Oh dammit. Thanks :smiley: