Why does eclipse keeps highlighting a method?

2019-07-31 17:40发布

问题:

I am trying to override the method onItemClick. I will put my imports and methods below:

import android.app.Activity;
import android.app.ListActivity;
import android.content.ContentUris;
import android.content.Intent;
import android.database.Cursor;
import android.net.Uri;
import android.os.Bundle;
import android.provider.Contacts.People;
import android.util.Log;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ListView;
import android.widget.SimpleCursorAdapter;
import android.widget.TextView;
import android.widget.AdapterView.OnItemClickListener;

public class ListViewActivityActivity extends ListActivity implements OnItemClickListener {

    @Override 
    public void onItemClick(AdapterView adview, View target, int position, long id) {}

}

My question is why does onItemClick method keep underlining? What am I doing wrong? I tried reloading project and it didn't help. Anybody run in to the same problem?

PS when I hover over it it says : The method onItemClick(AdapterView, View, int, long) of type ListViewActivityActivity must override a superclass method

回答1:

Your project has the Java compiler level set to 1.5. The @Override annotation is not allowed for a class implementing an interface method in Java 1.5; this is only allowed from Java 1.6 onward.

Go into your project properties (project's context menu), select Java Compiler and set the compiler compliance level to 1.6.



回答2:

You are using the non-generic type of AdapterView but the original method uses a generic type. It is allowed by the compiler, but not recommended.

This is the right way to override onItemClick :

@Override 
public void onItemClick(AdapterView<?> adview, View target, int position, long id) {}