NullPointerException with android.support.v7.widget.Toolbar

后端 未结 12 1015
旧巷少年郎
旧巷少年郎 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:31

    In my own case, i had used

    @Bind(R.id.toolbar)
    protected Toolbar toolbar;
    

    at the top of my code but forgot to do

    ButterKnife.bind(this);
    

    inside onCreate() method

    I hope that helps someone

    Remember to add

     compile 'com.jakewharton:butterknife:7.0.1'
    

    to your build.gradle dependencies and import

    import butterknife.Bind;
    import butterknife.ButterKnife;
    

    in your java code and rebuild your app.

提交回复
热议问题