-6

Hi I'm getting nullPointerException in my application with this line.

this.getSupportActionBar().setDisplayHomeAsUpEnabled(true);

this.getSupportActionBar().setBackgroundDrawable(new ColorDrawable(Color.GRAY));

I'm extending AppCompatActivity with my activity class.

My Logcat says as:

 Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'void android.support.v7.app.ActionBar.setDisplayHomeAsUpEnabled(boolean)' on a null object reference

Can you please help me clearing this issue???

Opiatefuchs
  • 9,800
  • 2
  • 36
  • 49
Parthiban M
  • 1,104
  • 1
  • 10
  • 30

1 Answers1

1

You have to set the supportActionBar:

mToolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(mToolbar);
Tom Sabel
  • 3,935
  • 33
  • 45