I receive the following error in Android Studio "Android Monitor"
There's a lot of mumbo-jumbo but it's essentially saying the cause of the error is the following:
Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'void android.support.v7.app.ActionBar.setDisplayHomeAsUpEnabled(boolean)' on a null object reference
at com.example.robthoms.photopop.SettingsActivity.onCreate(SettingsActivity.java:28)
I'm trying to make Settings work on the Toolbar and I got the code from:
https://www.androidhive.info/2017/07/android-implementing-preferences-settings-screen/
If you click on this link you'll see the entire code for SettingsActivity.java that I'm trying to use but when I click on "settings" in toolbar, App closes.
What is wrong with SettingsActivity that the app closes?
My AndroidManifest.xml:
My styles.xml
Hides ActionBar in classes while styles.xml has Light.DarkActionBar
ActionBar bar = getSupportActionBar () ;
if (bar != null) bar.hide () ;


The problem is caused because your activity do not have any ActionBar. In android manifest, make sure your activity is using the theme which has an
ActionBar. Make sure it doesn't have something likeNoActionBar. If your activity is not using any theme, check yourAppThemeinstyles.xml.One possible solution would be to use this in the manifest:
Another way:
Add new style in styles.xml:
And use new style in the manifest: