ActionBarActivity getSupportActionBar().hide() throws NullPointerException
android, android-actionbar-compat, android-support-library, java, nullpointerexception
Solution
meet the same problem ,but I use code to set fullscreen and noActionbar below instead of theme in xml:
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
getSupportActionBar().hide();
setContentView(R.layout.page_welcome);
initViews();
}
this code runs well before ICS but crashs caused by NullPointException above ICS,After some experiments,I got the solution:delete one line code which set no title as below:
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
// requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
getSupportActionBar().hide();
setContentView(R.layout.page_welcome);
initViews();
}
Then it works well at all platforms. : )
Problem
Call ``` if (getSupportActionBar() != null) getSupportActionBar().hide(); ``` or just: ``` getActionBar() ``` in android.support.v7.app.ActionBarActivity I get such exception: ``` ... java.lang.NullPointerException at android.support.v7.app.ActionBarImplICS.hide(ActionBarImplICS.java:302) at android.support.v7.app.ActionBarImplJB.hide(ActionBarImplJB.java:20) ... ``` EDIT: it just happens when activity have Theme: ``` <style name="MyTheme" parent="Theme.AppCompat.Light"> <item name="android:windowNoTitle">true</item> <item name="android:windowFullscreen">false</item> </style> ``` note: ``` getSupportActionBar() ``` do not return null