NullPointerException: with ActionBar.setDisplayHomeAsUpEnabled(boolean)' on a null object reference

前端 未结 7 950

I get this nullPointerException on runtime:

Caused by: java.lang.NullPointerException: Attempt to invoke virtual method \'void android.app.ActionB

7条回答
  •  不知归路
    2020-12-06 17:46

    You should try this one. I think it will work.

        Toolbar toolbar = findViewById(R.id.toolbar1);
        setSupportActionBar(toolbar);
    
        mDrawerLayout = findViewById(R.id.drawer_layout);
        mDrawerLayout = findViewById(R.id.drawer_layout);
        mDrawerLayout.setDrawerShadow(R.drawable.rectagle_with_black_outer,
                GravityCompat.START);
        getSupportActionBar().setDisplayHomeAsUpEnabled(true);
        getSupportActionBar().setHomeButtonEnabled(true);
    
        mDrawerToggle = new ActionBarDrawerToggle(this, mDrawerLayout,
                toolbar, R.string.navigation_drawer_close,
                R.string.navigation_drawer_close) {
            public void onDrawerClosed(View view) {
                invalidateOptionsMenu();
            }
    
            public void onDrawerOpened(View drawerView) {
                invalidateOptionsMenu();
            }
        };
    

提交回复
热议问题