NullPointException与getActionBar [英] NullPointException with getActionBar

查看:153
本文介绍了NullPointException与getActionBar的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有我的平板电脑界面(安卓> 3)一个非常奇怪的现象。 当我启动它,它就像一个机器人2 *界面底部的称号。 当然,当我打电话的getActionBar()返回一个空。

I have a really strange behaviour with my tablet interface (Android > 3). When I launch it, it's like a Android 2* interface with the title at the bottom. And of course when I call the getActionBar() it returns a null.

我最小的SDK和放大器;目标SDK被设定好,我使用SDK的Andr​​oid 3.0(11)。我在哪里错了?

My min-sdk & target-sdk are well set and I use the SDK Android 3.0 (11). Where am I wrong ?

public class MainScreenActivity extends Activity {

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.mainlayout);
    ActionBar bar = getActionBar();
    bar.setBackgroundDrawable(getResources().getDrawable(R.drawable.actionbar));

随着最后一行我得到这个错误:

With the last line I get this error :

Caused by: java.lang.NullPointerException
E/AndroidRuntime( 9082):    at com.shoppingscanner.tablet.MainScreenActivity.onCreate(MainScreenActivity.java:21)
E/AndroidRuntime( 9082):    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1050)
E/AndroidRuntime( 9082):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1782)
E/AndroidRuntime( 9082):    ... 11 more

我的清单(的Andr​​oid 3.0中使用):

My Manifest (Android 3.0 used) :

<uses-sdk
    android:minSdkVersion="5"
    android:targetSdkVersion="11" />

即使minSdk是11,我有这种行为。

Even if the minSdk is 11, I have this behaviour.

谢谢!

推荐答案

您还需要你的活动的窗口,有肉眼可见的称号。您可以采取的帮助 这里

You also need your Activity's window to have the title visible. you can take help from here

这篇关于NullPointException与getActionBar的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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