Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Android Implementing Designs for Android Customizing the Login Screen Hiding the Action Bar

Eric De Wildt
PLUS
Eric De Wildt
Courses Plus Student 13,077 Points

ActionBar Nullpointer in Android Studio.

The code in this video gives me a Nullpointer exception and causes the application to freeze upon installation. I tried using a if/else statement to determine if the action bar was showing and is so then to hide it. That didn't work either. Please help.

6 Answers

This is what you should use:


android.support.v7.app.ActionBar actionBar = getSupportActionBar(); actionBar.hide();


Sam McDavid
Sam McDavid
20,242 Points

I have been testing on emulators with 4.4.4 and 5.0.0 and I have found the only thing that I need to do is extend Activity instead of ActionBarActivity:

public class LoginActivity extends Activity {

and

public class SignUpActivity extends Activity {

No further code is needed in order to hide the action bar.

You can still use the code that Ben shows you, but be sure to check for null before calling hide

ActionBar actionBar = getActionBar();
if (actionBar != null) {
    actionBar.hide();
}

Good luck!

Please show us your code.

Eric De Wildt
PLUS
Eric De Wildt
Courses Plus Student 13,077 Points

I would show the code but I figured it out on my own. Instead of using the code in the tutorial I changed the base theme in the manifest for the two activities I don't need the action bar to one with no action bar.

Thomas Wang
Thomas Wang
11,335 Points

If your activity extends android.support.v7.app.ActionBarActivity, try getSupportActionBar() instead of getActionBar().

Thanks Sam! It worked great!