getActionBar()空指针异常

简介: 网上的各种解决方案已经不少了,但是不适合于我的,谷歌一种新的解决方案    you can directly specify it in manifest file 1 2 3 4 There are 3 themes available Theme.

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

  

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

Screenshot from 2013-01-16 12:40:47

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  

目录
相关文章
|
3月前
|
Kubernetes 关系型数据库 MySQL
seata启动问题之指针异常如何解决
Seata是一款开源的分布式事务解决方案,旨在提供高效且无缝的分布式事务服务;在集成和使用Seata过程中,开发者可能会遇到不同的异常问题,本合集针对Seata常见异常进行系统整理,为开发者提供详细的问题分析和解决方案,助力高效解决分布式事务中的难题。
65 0
项目中常见NPE空指针异常
项目中常见NPE空指针异常
|
2月前
|
安全 IDE Java
终结空指针异常:Java开发者的生存指南
终结空指针异常:Java开发者的生存指南
57 1
|
2月前
|
安全 IDE Java
【2024java面试题无需C币下载】终结空指针异常:Java开发者的生存指南
【2024java面试题无需C币下载】终结空指针异常:Java开发者的生存指南
45 1
|
4月前
|
Java
又是把Java基础知识学废的一天,new 一个对象数组,操作时报空指针异常
又是把Java基础知识学废的一天,new 一个对象数组,操作时报空指针异常
36 0
|
4月前
|
存储 缓存 NoSQL
SpringBoot整合Redis调用lua脚本出现空指针异常(序列化器问题)
一、问题描述 业务中出现需要保证原子性的一系列缓存操作,所以决定使用lua脚本来保证原子性。 但是调用过程中lua脚本抛出了异常:attempt to perform arithmetic on local ‘xxx’ (a nil value) 发生异常的lua脚本代码(部分)
|
4月前
|
Java Spring
SpringMVC控制层private方法中出现注入的service对象空指针异常
一、现象 SpringMVC中controller里的private接口中注入的service层的bean为null,而同一个controller中访问修饰符为public和protected的方法不会出现这样的问题。 controller中的方法被AOP进行了代理,普通Controller如果没有AOP,private方法中bean也是正常的。
|
7月前
|
存储 Java 开发者
使用Optional优雅避免空指针异常
在编程世界中, 空指针异常(NullPointerException) 无疑是我们最常遇到的"罪魁祸首"之一。它像一片隐蔽的地雷,静静地等待着我们不小心地踏入,给我们的代码带来潜在的威胁。这种问题虽然看似微小,但却无法忽视。甚至可能对整个程序的稳定性产生重大影响。
33 0
|
8月前
|
Java
如何优雅的避免Java中:NullPointerException(空指针异常)
如何优雅的避免Java中:NullPointerException(空指针异常)
64 0
|
8月前
|
Java 容器
JavaMailSender发送邮件(整合SpringBoot、解决空指针异常问题)
一、邮箱开启SMTP服务 以qq邮箱为例 进入邮箱设置页面后选择账户