如何从onCreate()内部调用该函数...我想从oncreate()调用CreateSharedactionprovider()但应用程序崩溃...我没有正确调用函数或缺少一些争论
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_camera);
// Show the Up button in the action bar.
setupActionBar();
CreateSharedactionprovider();
}
@TargetApi(Build.VERSION_CODES.ICE_CREAM_SANDWICH)
public boolean CreateSharedactionprovider(Menu menu){
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) {
// Locate MenuItem with ShareActionProvider
MenuItem item = menu.findItem(R.id.menu_share);
// Fetch and store ShareActionProvider
mShareActionProvider = (ShareActionProvider) item.getActionProvider();
doShare();
}
return true;
}
答案 0 :(得分:2)
CreateSharedActionprovider将Menu作为参数,但您在没有任何参数的情况下调用它。看起来您的菜单为空,并且您正尝试在其上调用findItem。