Why does eclipse keeps highlighting a method?

╄→гoц情女王★ 提交于 2019-12-11 07:45:36

问题


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) {}


来源:https://stackoverflow.com/questions/9213421/why-does-eclipse-keeps-highlighting-a-method

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!