Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What to use instead of getSupportActionBar() in Library 22?

There is a line in my code, that marked as yellow:

getSupportActionBar().setDisplayShowHomeEnabled(true);

After installing appcompat-v7:22.1 it shows a hint:

"Method invocation may produce java.lang.nullpointerexception".

What should be used instead of getSupportActionBar()?

like image 639
Ardi Avatar asked Dec 02 '22 17:12

Ardi


1 Answers

getSupportActionBar().setDisplayShowHomeEnabled(true);

Should say

if (getSupportActionBar() != null)
{
   getSupportActionBar().setDisplayShowHomeEnabled(true);
}

getSupportActionBar() can return null so you the hint is telling you about this.

like image 103
apmartin1991 Avatar answered Feb 25 '23 20:02

apmartin1991