且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

ActionBarActivity getSupportActionBar()。隐藏()抛出NullPointerException异常

更新时间:2023-11-19 12:34:28

满足同样的问题,但我用code设置全屏和noActionbar下方,而不是主题的xml:

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();
}

这code运行良好ICS之前,但crashs上述ICS造成NullPointException,一些实验后,我得到了解决:删除一行code的设置没有标题如下:

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. : )