NullPointerException with android.support.v7.widget.Toolbar

后端 未结 12 1016
旧巷少年郎
旧巷少年郎 2021-01-07 17:53

I am currently trying to implement a navigation drawer in my app. I am having an issue with the Toolbar being null. I have done many searches online and tried many different

12条回答
  •  忘掉有多难
    2021-01-07 18:23

    Answer is a little late but I just ran into this problem.

    I had a similar issue and spent 7 hrs messing with it. It worked on 3 of 4 activities just fine but one would crash.

    The only thing that worked for me, and I am not sure why, was to put the:

        mToolbar = (Toolbar) findViewById(R.id.toolbar);
        setSupportActionBar(mToolbar);
        getSupportActionBar().setDisplayShowHomeEnabled(true); 
    

    as the last code in my onCreate. It works perfectly now.

提交回复
热议问题