• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

Apps java.lang.nullpointer exception

vedavathi

Lurker
I am an android beginner, created my project using api level 11 in android studio.I want to customize the action bar but if i perform any method it is showing errors like R can not be resolved
setContentView(R.layout.activity_main);

ActionBar ab=getActionBar();
ab.setHomeButtonEnabled(true);
Method invocation may produce java.lang.nullpointer exception
Please help me.
 
The 'R' class is an automatically generated piece of code, based on your defined layouts. If it can't be resolved this means the build process hasn't generated it. This is usually due to some errors in your layout definition files. Check for problems reported in Android Studio.

Null pointer errors are run time problems. But I'm slightly confused, as it sounds like you haven't got as far as deploying and running your app on a device yet.
 
I think he is talking about Android Studio saying that "Method invocation may produce java.lang.nullpointer exception", not that he is actually running the program and getting the NullPointer, not sure though.
 
You are recommended to use getSupportActionBar() instead of getActionBar() if you are using appcompact ActionbarActivity.
 
Last edited:
Back
Top Bottom