解决getActionBar()报NullPointerException办法
2017-04-19 23:57
302 查看
1. 加载完视图后,再去获取:
必须在setContentView()后面。
2.sdk版本:
Actionbar的主题在3.0以后才有,使用的时候要确保,最低的版本不能小于3.0。
[html] view
plain copy
print?
<uses-sdk
android:minSdkVersion="11"
android:targetSdkVersion="17" />
3.
(下面这俩一定要)配置清单中,添加的主题:
[html] view
plain copy
print?
android:theme="@style/AppTheme" >
其父主题要具有ActionBar,例如:
[html] view
plain copy
print?
<style name="AppTheme" parent="@android:style/Theme.Holo.Light">
4.活动类及其父类中,不要设置为全屏:
[html] view
plain copy
print?
//getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
以上基本可解决, 若尚未解决, 再试试下面方法:
5.没有引用到v11+包中的主题。
values-v11中主题:
[html] view
plain copy
print?
<resources>
<!--
Base application theme for API 11+. This theme completely replaces
AppBaseTheme from res/values/styles.xml on API 11+ devices.
-->
<style name="AppBaseTheme" parent="android:Theme.Holo.Light">
<!-- API 11 theme customizations can go here. -->
</style>
</resources>
所以,如果遇到报空的问题,你看看你的工程中有没有values-v11或者v14的包,没有的话就去其他工程中copy一份过来,改下就可以了
必须在setContentView()后面。
2.sdk版本:
Actionbar的主题在3.0以后才有,使用的时候要确保,最低的版本不能小于3.0。
[html] view
plain copy
print?
<uses-sdk
android:minSdkVersion="11"
android:targetSdkVersion="17" />
3.
(下面这俩一定要)配置清单中,添加的主题:
[html] view
plain copy
print?
android:theme="@style/AppTheme" >
其父主题要具有ActionBar,例如:
[html] view
plain copy
print?
<style name="AppTheme" parent="@android:style/Theme.Holo.Light">
4.活动类及其父类中,不要设置为全屏:
[html] view
plain copy
print?
//getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
以上基本可解决, 若尚未解决, 再试试下面方法:
5.没有引用到v11+包中的主题。
values-v11中主题:
[html] view
plain copy
print?
<resources>
<!--
Base application theme for API 11+. This theme completely replaces
AppBaseTheme from res/values/styles.xml on API 11+ devices.
-->
<style name="AppBaseTheme" parent="android:Theme.Holo.Light">
<!-- API 11 theme customizations can go here. -->
</style>
</resources>
所以,如果遇到报空的问题,你看看你的工程中有没有values-v11或者v14的包,没有的话就去其他工程中copy一份过来,改下就可以了
相关文章推荐
- JavaWeb学习(5.5)---在Servlet使用getServletContext()获取ServletContext对象出现java.lang.NullPointerException(空指针)异常的解决办法
- 在Servlet使用getServletContext()获取ServletContext对象出现java.lang.NullPointerException(空指针)异常的解决办法
- 在Servlet使用getServletContext()获取ServletContext对象出现java.lang.NullPointerException(空指针)异常的解决办法
- 在Servlet使用getServletContext()获取ServletContext对象出现java.lang.NullPointerException(空指针)异常的解决办法
- 在Servlet使用getServletContext()获取ServletContext对象出现java.lang.NullPointerException(空指针)异常的解决办法
- getActionBar为null的解决办法
- 在Servlet使用getServletContext()获取ServletContext对象出现java.lang.NullPointerException(空指针)异常的解决办法
- 在Servlet使用getServletContext()获取ServletContext对象出现java.lang.NullPointerException(空指针)异常的解决办法
- 在Servlet使用getServletContext()获取ServletContext对象出现java.lang.NullPointerException(空指针)异常的解决办法
- getActionBar()返回为空 空指针错误 Caused by: java.lang.NullPointerException
- 关于使用super.getHibernateTemplate()中的方法报java.lang.NullPointerException的解决办法
- 在Servlet使用getServletContext()获取ServletContext对象出现java.lang.NullPointerException(空指针)异常的解决办法
- 在Servlet使用getServletContext()获取ServletContext对象出现java.lang.NullPointerException(空指针)异常的解决办法
- 在Servlet使用getServletContext()获取ServletContext对象出现java.lang.NullPointerException(空指针)异常的解决办法
- getHibernateTemplate()中的方法报java.lang.NullPointerException的解决办法
- 在Servlet使用getServletContext()获取ServletContext对象出现java.lang.NullPointerException(空指针)异常的解决办法
- 隐藏actionBar, 报错 getActionBar.hide() 运行时java.lang.NullPointerException
- 在Servlet使用getServletContext()获取ServletContext对象出现java.lang.NullPointerException(空指针)异常的解决办法
- getActionBar为null的解决办法
- Struts2中使用execAndWait后,在 Action中调用getXXX()方法报告java.lang.NullPointerException异常的原因和解决方法