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 trialEric De Wildt
Courses Plus Student 13,077 PointsActionBar 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
Unsubscribed User
6,718 PointsThis is what you should use:
android.support.v7.app.ActionBar actionBar = getSupportActionBar(); actionBar.hide();
Sam McDavid
20,242 PointsI 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!
Alexandre Juca
Courses Plus Student 3,222 PointsPlease show us your code.
Eric De Wildt
Courses Plus Student 13,077 PointsI 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
11,335 PointsIf your activity extends android.support.v7.app.ActionBarActivity, try getSupportActionBar() instead of getActionBar().
rtrind
6,358 PointsThanks Sam! It worked great!