我有一个问题。此代码在我的 nexus 10 android 4.2.1 上运行良好。但是在 AVD android 2.3 上它给了我
NullPointerException com.example.training.ContentFragment.onCreateOptionsMenu(ContentFragment.java:97)
所以我有两个导航选项卡,每个选项卡有两个 fragment 。
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
// Inflate the menu; this adds items to the action bar if it is present.
activity.getSupportMenuInflater().inflate(R.menu.trainings_menu, menu);
super.onCreateOptionsMenu(menu, inflater);
}
有人可以帮我解决这个问题吗?
最佳答案
onCreateOptionsMenu(Menu menu, MenuInflater inflater)
该方法已经自带了MenuInflater的引用,不需要调用,直接使用提供的即可
@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
super.onCreateOptionsMenu(menu, inflater);
inflater.inflate(R.menu.activity_main, menu);
}
关于java - android 中的导航选项卡在膨胀菜单时出现 ABS nullpointerexception,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14620518/