错误抽屉式导航栏 [英] Error in Navigation Drawer

查看:216
本文介绍了错误抽屉式导航栏的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

不知怎的,我得到一个空指针异常此方法中

  @覆盖
保护无效onPostCreate(捆绑savedInstanceState){
    super.onPostCreate(savedInstanceState);
    actionBarToggle.syncState();
}

actionBarToggle.syncState()在这有一个空指针异常。

现在,如果我注释掉这再有就是空指针异常,当我触碰动作条,打开抽屉式导航

 如果(actionBarToggle.onOptionsItemSelected(项目)){
        返回true;
    }


解决方案

我发现这个问题实际上我在做这个

  actionBarToggle =新ActionBarDrawerToggle(这一点,drawerLayout,
            R.drawable.ic_drawer,R.string.drawerOpen,R.string.drawerClose){
        公共无效onDrawerClosed(查看视图){
            getSupportActionBar()的setTitle(关)。
            ActivityCompat.invalidateOptionsMenu(活动);
        }        公共无效onDrawerOpened(查看主){
            getSupportActionBar()的setTitle(打开)。
            ActivityCompat.invalidateOptionsMenu(活动);
        }
    };
    drawerLayout.setDrawerListener(actionBarToggle);
    drawerLayout =(DrawerLayout)findViewById(R.id.navigationDrawer); //这应该是actionBarToggle前

于是我就在actionBarToggle使用后intailizing的drawerLayout。

Somehow I am getting a null pointer Exception in this method

@Override
protected void onPostCreate(Bundle savedInstanceState) {
    super.onPostCreate(savedInstanceState);
    actionBarToggle.syncState();
}

actionBarToggle.syncState() in this there is a null pointer exception.

Now if I comment out this then there is null pointer exception when i touch the actionbar to open navigation drawer

    if (actionBarToggle.onOptionsItemSelected(item)) {
        return true;
    }

解决方案

I found the problem actually I was doing this

        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

So I was intailizing the drawerLayout after using it in actionBarToggle.

这篇关于错误抽屉式导航栏的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆