超级没有在android中调用异常?

时间:2015-03-23 06:00:15

标签: android

这是我的代码

@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"我看到了类似问题的答案,但我没有得到它请所有帮助赞赏。谢谢。

1 个答案:

答案 0 :(得分:2)

在覆盖它之前,必须从父类调用super方法。

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

希望这对你有用。