Should I null check the getSupportActionBar()
method even if earlier in that method I have set the support action bar using getSupportActionBar()
?
In onCreate()
I have the three lines
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
getSupportActionBar().setTitle(getIntent().getStringExtra(TITLE_KEY));
Android Studio then gives me the warning
"Method invocation may produce java.lang.NullPointerException"
Assuming that the findViewById method does return a valid ToolBar
object, do I still need to null check the getSupportActionBar()
method or is it safe to just ignore the warning?