NullPointerException on a page [duplicate]


NullPointerException on a page [duplicate]



This question already has an answer here:



So basically I am trying to implement this tutorial here:
https://github.com/medyo/android-about-page



I have added the necessary dependencies in gradle. However when I open my AboutCreator Activity my app crashes



Code for AboutCreatorActivity


public class AboutCreatorActivity extends AppCompatActivity {

@RequiresApi(api = Build.VERSION_CODES.LOLLIPOP)
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_about_creator);
//setTitle("About Page");
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
getWindow().getDecorView().setSystemUiVisibility(
View.SYSTEM_UI_FLAG_LAYOUT_STABLE
| View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN);

FancyAboutPage fancyAboutPage=findViewById(R.id.fancyaboutpage);
//fancyAboutPage.setCoverTintColor(Color.BLUE); //Optional
fancyAboutPage.setCover(R.drawable.coverimg);
fancyAboutPage.setName("Shashank Singhal");
fancyAboutPage.setDescription("Google Certified Associate Android Developer | Android App, Game, Web and Software Developer.");
fancyAboutPage.setAppIcon(R.drawable.cakepop);
fancyAboutPage.setAppName("Cake Pop Icon Pack");
fancyAboutPage.setVersionNameAsAppSubTitle("1.2.3");
fancyAboutPage.setAppDescription("Cake Pop Icon Pack is an icon pack which follows Google's Material Design language.nn" +
"This icon pack uses the material design color palette given by google. Every icon is handcrafted with attention to the smallest details!nn"+
"A fresh new take on Material Design iconography. Cake Pop offers unique, creative and vibrant icons. Spice up your phones home-screen by giving it a fresh and unique look with Polycon.");
fancyAboutPage.addEmailLink("david_g@hotmail.co.uk");
fancyAboutPage.addFacebookLink("https://www.facebook.com/david.g.161");
fancyAboutPage.addLinkedinLink("https://www.linkedin.com/in/davidg1/");
//fancyAboutPage.addGitHubLink("https://github.com/Shashank02051997");

}
}



ERROR:


07-01 14:44:17.090 26813-26813/net.simplifiedlearning.firebaseauth E/AndroidRuntime: FATAL EXCEPTION: main
Process: net.simplifiedlearning.firebaseauth, PID: 26813
java.lang.RuntimeException: Unable to start activity ComponentInfo{net.simplifiedlearning.firebaseauth/net.simplifiedlearning.firebaseauth.AboutCreatorActivity}: java.lang.NullPointerException: Attempt to invoke virtual method 'void android.support.v7.app.ActionBar.setDisplayHomeAsUpEnabled(boolean)' on a null object reference
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2822)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2897)
at android.app.ActivityThread.-wrap11(Unknown Source:0)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1598)
at android.os.Handler.dispatchMessage(Handler.java:105)
at android.os.Looper.loop(Looper.java:251)
at android.app.ActivityThread.main(ActivityThread.java:6572)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:240)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:767)
Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'void android.support.v7.app.ActionBar.setDisplayHomeAsUpEnabled(boolean)' on a null object reference
at net.simplifiedlearning.firebaseauth.AboutCreatorActivity.onCreate(AboutCreatorActivity.java:19)
at android.app.Activity.performCreate(Activity.java:6975)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1214)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2775)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2897) 
at android.app.ActivityThread.-wrap11(Unknown Source:0) 
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1598) 
at android.os.Handler.dispatchMessage(Handler.java:105) 
at android.os.Looper.loop(Looper.java:251) 
at android.app.ActivityThread.main(ActivityThread.java:6572) 
at java.lang.reflect.Method.invoke(Native Method) 
at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:240) 
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:767) 



This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.





Are you having toolbar in your activity ? getSupportActionBar() returns you null. It means you dont have toolbar in the layout.
– pop
Jul 1 at 13:52






No I do not have toolbar. How can I remove this?
– David G
Jul 1 at 13:54





remove this line getSupportActionBar().setDisplayHomeAsUpEnabled(true);
– pop
Jul 1 at 13:55





Brillitant! Thank you
– David G
Jul 1 at 13:58





Accept this answer if it solved your problem.
– pop
Jul 1 at 14:05




1 Answer
1



remove this line getSupportActionBar().setDisplayHomeAsUpEnabled(true);

Popular posts from this blog

How to add background colour in existing image using Swift?

Moria Casán

How to make file upload 'Required' in Contact Form 7?