getActionBar()空指针异常

网上的各种解决方案已经不少了,但是不适合于我的,谷歌一种新的解决方案

  

you can directly specify it in manifest file


1

2

3

4

<application

        android:icon="@drawable/app_icon"

        android:label="@string/app_name"

        android:theme="@android:style/Theme.Holo.Light" >

There are 3 themes available Theme.Holo.Light/Theme.Holo.Dark/Theme.Holo.Light.DarkActionBar.

Theme.Holo.Light requires API level >=11 while Theme.Holo.Dark/Theme.Holo.Light.DarkActionBar requires API level >= 14

If you want to change themes according to API level, you can specify a base appTheme, and override it in style files


1

2

3

4

<application

        android:icon="@drawable/app_icon"

        android:label="@string/app_name"

        android:theme="@style/appTheme" >

values/styles.xml


1

2

3

4

5

6

7

8

9

10

11

12

13

14

<resources>

    <!--

        Base application theme, dependent on API level.

    -->

    <style name="AppBaseTheme" parent="android:Theme.Light">

   

    </style>

    <style name="AppTheme" parent="AppBaseTheme">

       

    </style>

</resources>

values-v14/styles.xml


1

2

3

4

5

6

7

8

9

10

11

<resources>

    <!--

        Base application theme for API 14+. This theme completely replaces

        AppBaseTheme

    -->

    <style name="AppBaseTheme" parent="android:Theme.Holo.Light.DarkActionBar">

       

    </style>

</resources>

If you want a consistent theme while maintain compatibility with lower API levels, look at what these people are doing op

The second solution is to request ActionBar feature manually instead making the theme do it for you. I am too lazy to try it myself. This link explain it pretty well. op

时间: 2025-01-04 22:44:43

getActionBar()空指针异常的相关文章

getActionBar()为null的解决方法总结(引用他人)

最近在看android actionBar的使用,环境为AndroidStudio,建一个简单的工程,功能为:两个按钮,一个单击用于显示actionbar,一个用于隐藏actionbar.默认actiobar显示.理想状况如下图所示: 建好工程并运行,发现actionbar默认不显示(不显示上图所示的hello部分),如下图所示: 且单击"显示actionBar"的按钮后出现异常:如下图所示: 发现,是java.lang.NullPointerException引起的,到代码里面发现代

【Android】getActionBar()为null的解决方法总结

前言 在使用 ActionBar的时候,有时候会爆出空指针异常,这是由于应用没有获取到 ActionBar 导致的,而导致应用没有获取到 ActionBar 的原因比較多.所以我们以下就来总结一下 ActionBar 获取不到的错误原因. 解决的方法 检查你的应用是否设置了没有 ActionBar 的主题Theme.或者直接设置了 NoActionBar或NoTitleBar 属性,主要要检查这几点:检查 AndroidManifest.xml 中的 标签中的theme属性.然后检查各个 Act

[解决方法]Hibernate查询部分字段(含外键)出错,报空指针异常

假设当前表结构如下: food表字段有foodid,name,外键businessid,外键type business表字段有,name,外键type type表字段有id,name,foodid Hibernate生成的对应POJO分别是Food,Business,Type 需要查询food表部分字段,如name和外键businessid 则可在Food类中添加只有相应成员变量的构造方法,Food(String name,Business business) 使用hql语句 select ne

java 空指针异常造成的原因有哪些

实际上 空指针异常   也就是你用了一个没有实际值的对象 1. 某一对象没有被实例化,就拿来使用,如调用此对象的方法,会抛空指针异常. 2. 获取从别的对象传过来的对象为空 3. 数据库查询方面的空指针异常,数据库中储存的值为null或不存在 4.  结果集   rs   是空的啊或者未初始化就被调用了 昨天我就因为  数据库查询方面的空指针异常  造成页面加载不出来..呜呜呜呜 目前我认为就这些了,大家认为还有哪些请补充 java 空指针异常造成的原因有哪些,布布扣,bubuko.com

空指针异常

如果你对null 进行操作就会产生空指针异常Object obj = new Object();你要知道 obj是一个Object指针变量,指向Object类的一个实例我们说obj是一个对象 实质是它指向一个对象的首地址 如果这个指针变量obj 没有指向任何空间 你调用它的方法和属性就会出错例如 Object obj = new Object(); obj.equals("123");这个是没错的但换下面语句 Object obj = null; obj.equals("12

给ViewPager设置adapter出现空指针异常 解决

问题描述: TopNewsAdapter topNewsAdapter = new TopNewsAdapter();System.out.println("11111111" + topNewsAdapter == null);// 返回false,表明topNewsAdapter 不为空System.out.println("11111111" + mViewPager == null);// 返回false,表明mViewPager 不为空mViewPager

jsp &lt;input type=&quot;checkbox&quot;&gt;标记的空指针异常

今天看到书上的一段代码是这样的: 这是<input  type="checkbox">标记的代码 <br>选择你喜欢的歌手: <input type="checkbox" name="singer" value="张">张歌手 <input type="checkbox" name="singer" value="李">

Spring+Struts 2 简单实例报空指针异常

空指针出现于Action注入位置..如果一般错误请检查配置文件. 我出的错误.在于拷贝了之前做的实例中的lib文件夹到这个工程中. 其中有个包为struts2-convention-plugin-2.3.16.3.jar 造成了包识别异常.出现空指针.有类似经历的可以查看,也给大家提个醒.不要一气呵成的导入所有包.容易出现混乱.也不利于大家清楚的认识包和代码的联系. Spring+Struts 2 简单实例报空指针异常,布布扣,bubuko.com

getActionBar().setTitle(); Java.lang.NullPoint异常解决方案

getActionBar().setTitle(); Java.lang.NullPoint异常解决方案,是由于低版本不支持直接获取的缘故,修改方案: try changing your theme to this <style name="AppTheme" parent="android:Theme.Holo.Light.DarkActionBar"> and not the AppCompat Version 另外一种情况,如果是低版本,API低于