0

I have two parts of codes. One has the error, but the other doesn't.

ActionBar theActionBar = getSupportActionBar();
if (theActionBar != null) {
    // error: non-static method cannot be referenced from a static context
    ActionBar.setDisplayHomeAsUpEnabled(true);
}

.

getSupportActionBar().setDisplayHomeAsUpEnabled(true);

.

Does anyone happen to know how to explain this?

Leonard
  • 183
  • 1
  • 11

1 Answers1

1

Your error says it all. Just change this line:

ActionBar.setDisplayHomeAsUpEnabled(true);

to

theActionBar.setDisplayHomeAsUpEnabled(true);

or just change your code to look like this:

if(getSupportActionBar() != null)
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
Nongthonbam Tonthoi
  • 12,667
  • 7
  • 37
  • 64