gpt4 book ai didi

android - super 不在android中调用异常?

转载 作者:行者123 更新时间:2023-11-29 20:50:45 28 4
gpt4 key购买 nike

这是我的代码

@Override
public void onCreate(Bundle SavedInstanceState){
//Add this line in order for this fragment to handle menu events.
setHasOptionsMenu(true);
}

@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater){
inflater.inflate(R.menu.forecastfragment, menu);
}

public boolean onOptionItemSelected(MenuItem item){
//Handle action bar item clicks here. The action bar will
//automatically handle clicks on the Home/Up button, so long
//as you specify a parent activity in AndroidManifest.xml
int id=item.getItemId();
if (id==R.id.action_refresh){
FetchWeatherTask weatherTask=new FetchWeatherTask();
weatherTask.execute();
return true;
}
return super.onOptionsItemSelected(item);
}

当我执行此操作时,我得到一个“app.SuperNotCalledException”,我看到了类似问题的答案,但我没有得到它。请大家帮忙,谢谢。谢谢。

最佳答案

你必须调用super在重写之前从父类中获取方法。

@Override
public void onCreate(Bundle SavedInstanceState){
super.onCreate(savedInstanceState);
//Add this line in order for this fragment to handle menu events.
setHasOptionsMenu(true);
}

希望这对你有用。

关于android - super 不在android中调用异常?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29204066/

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