Android Error [Attempt to invoke virtual method 'void android.app.ActionBar' on a null object reference]

后端 未结 24 1969
误落风尘
误落风尘 2020-11-28 22:13

I have a code module which implements viewpager with navigation drawer, however, when I run the code I get the following error

01-26 09:20:02.958: D/AndroidR         


        
24条回答
  •  清酒与你
    2020-11-28 22:53

    In my case I had the same error but my mistake was that I didn't declare my Toolbar.

    So, before I use getSupportActionBar I had to find my toolbar and set the actionBar

        appbar = (Toolbar) findViewById(R.id.toolbar);
        setSupportActionBar(appbar);
    
        getSupportActionBar().setHomeAsUpIndicator(R.drawable.ic_nav_menu);
        getSupportActionBar().setDisplayHomeAsUpEnabled(true);
    

提交回复
热议问题