gpt4 book ai didi

java - @override 方法不会覆盖或实现父类(super class)型的方法

转载 作者:行者123 更新时间:2023-11-30 08:58:52 25 4
gpt4 key购买 nike

我在 android 编码方面遇到了一个小问题。我对此还是很陌生,遇到了一个小问题。无论我做什么,我似乎都无法清除我的@override 上的错误。错误是@override 方法没有覆盖或实现父类(super class)型的方法,错误出现在最后 3 个 @Override 中的所有 3 个上。通过它,它为 Menu、menu、MenuItem、itmsearch 和 KeyEvent 提出了一个错误,说找不到符号。任何帮助都将非常有用,在此先感谢您。

import android.os.Bundle;
import android.widget.ArrayAdapter;

public class MainActivity extends ListActivity
{


/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);

super.setTitle("My Films");

setContentView(R.layout.main);

setListAdapter(new ArrayAdapter<String>(this,
R.layout.film_list_cell,
R.id.text,
CELLS));

}

@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.main_menu, menu);
return true;
}
@Override
public boolean onOptionsItemsSelected(MenuItem item) {
if (item.getItemId() ==R.id.itmsearch) {
onSearchRequested();
return true;
}
return false;
}
@Override
public boolean onKeyUp(int keyCode, KeyEvent event) {
if( keyCode == KeyEvent.KEYCODE_SEARCH) {
onSearchRequested();
return true;
}
return false;
}



static final String[] CELLS =
new String[] {"Cell 0", "Cell 1", "Cell 2",
"Cell 3", "Cell 4", "Cell 5",
"Cell 6", "Cell 7", "Cell 8",
"Cell 9", "CEll 10"};
}

最佳答案

onOptionsItemsSelected 更改为 onOptionsItemSelected .
...................................................^

这是您要覆盖的方法的正确名称:

public boolean onOptionsItemSelected (MenuItem item)

编辑:

Through that it comes up with an error for Menu, menu, MenuItem, itmsearch and KeyEvent saying cannot find symbol.

确保导入所有相关类:

import android.view.Menu;
import android.view.KeyEvent;
import android.view.MenuItem;

关于java - @override 方法不会覆盖或实现父类(super class)型的方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27463173/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com