的getAction酒吧给空指针异常 [英] getAction Bar gives null pointer exception

查看:124
本文介绍了的getAction酒吧给空指针异常的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在Android的动作栏中工作。 为了这个,我用

i want to work with action bar in android. for this i use

getActionBar().setHomeButtonEnabled(true);

在下面的setContentView。但让我空指针异常。 当我尝试只getActionBar(),它工作正常。

below the SetContentView . but is gives me null pointer exception. when i try only getActionBar() it works fine.

请帮助我。

推荐答案

如果你的活动不具有标题栏的方法 getActionBar() 可以返回null。

If your activity does not have a title bar the method getActionBar() can return null.

您有两个选项来解决这个问题:

You have two options to fix this:

1添加 getWindow()requestFeature(Window.FEATURE_ACTION_BAR); 的setContentView

2-在你的清单指定支持主题动作条

2- In your Manifest specify a Theme that supports ActionBar

另外,还要确保你的目标正确的Andr​​oid版本,例如<使用-SDK安卓的minSdkVersion =11/>

Also make sure that you are targeting the right android version e.g. <uses-sdk android:minSdkVersion="11" />

这篇关于的getAction酒吧给空指针异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆