In my case is because of styles.xml
set the wrong parent theme, i.e. NoActionBar
theme of course getSupportActionbar()
is null:
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
Changed it to something else fixed it:
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">