不知何故,我在此方法中得到一个空指针异常
@Override
protected void onPostCreate(Bundle savedInstanceState) {
super.onPostCreate(savedInstanceState);
actionBarToggle.syncState();
}
actionBarToggle.syncState()
中存在一个空指针异常。现在,如果我对此进行注释,则在我触摸操作栏以打开导航抽屉时会出现空指针异常
if (actionBarToggle.onOptionsItemSelected(item)) {
return true;
}
最佳答案
我发现问题实际上是我在这样做
actionBarToggle = new ActionBarDrawerToggle(this, drawerLayout,
R.drawable.ic_drawer, R.string.drawerOpen, R.string.drawerClose) {
public void onDrawerClosed(View view) {
getSupportActionBar().setTitle("Close");
ActivityCompat.invalidateOptionsMenu(activity);
}
public void onDrawerOpened(View main) {
getSupportActionBar().setTitle("Open");
ActivityCompat.invalidateOptionsMenu(activity);
}
};
drawerLayout.setDrawerListener(actionBarToggle);
drawerLayout = (DrawerLayout) findViewById(R.id.navigationDrawer);//This should be before actionBarToggle
因此,在actionBarToggle中使用了抽屉布局之后,我开始细化它。