造成这种结果一般有3中情况 第一是:未加载布局文件,也就是没有设置布局之前,就findViewById(),这样肯定获取不到了,这第二是:View应该是树形的组织,从当前所在的contentview中找不到,要设置contentview为包含有所要find的contentview; 第三是:Eclipse造成的;项目clean一次(Project菜单 -> Clean子菜单),就OK了。 ? 改用下面的格式就OK了 final LinearLayout choose = (LinearLayout) getLayoutInflater().inflate(R.layout.choose_header, null);
final Gallery gallery = (Gallery) choose.findViewById(R.id.gallery1);
详细解决方案
android:通过findViewById试图获取界面元素对象为Null,运行会提示空指针错误
热度:96 发布时间:2016-05-01 12:30:09.0
相关解决方案
- struts2 对象属性流入不进去, 报错:target is null for setProperty(null, "x" [Ljava.lang.Stri
- SSH有关问题,There is no Action 地图ped for action name null
- !使用JDNI时,报 Cannot create JDBC driver of class '' for connect URL 'null'
- java.sql.SQLException: The url cannot be null 谋求帮助
- null id in com.bsw.gms.hibernate.pojo.Score entry (don't flush the Session after an exception occurs,该怎么解决
- 急紧急十分紧急JSP,「focus="<%= JspUtil.getFirstProperty(request, null) %>」哪位高手给解释上这句话的作用?一有答案立即结帖
- ognl.OgnlException: target is null for setProperty,该怎么解决
- 关于异常:attempt to create delete event with null entity
- log4j:ERROR setFile(null,false) call failed.解决方法
- 'null' 为空或不是对象?该怎么处理
- org.hibernate.PropertyAccessException: Null value was assigned to a property of解决办法
- org.apache.jasper.JasperException: java.lang.NumberFormatException: null,该怎么解决
- android 读取byte[]中的元素解决方案
- android 标题栏兑现方式
- android 中Activity向BroadcastReceiver发送数据,该怎么解决
- Android 4.0 为什么模拟器老是提示小弟我谷歌拼音输入法已停止
- null == a 跟 a == null 的区别
- android:getSharedPreferences() 这是哪个类的方法解决思路
- android 怎么判断一个程序是否联网
- android 大量数据按周分组,该如何解决
- org.apache.jasper.JasperException: java.lang.NumberFormatException: null,该如何解决
- android RadioButton如何设置默认选中
- ksoap2-android-这个包,连接webService怎么设置超时
- android 怎么重新设置锚点
- android UI界面设计解决方案
- android 图片对象获取的有关问题
- android 怎么调用淘宝支付宝接口
- Android 沿袭InputMethodService自定义输入法
- android 关于服务连接的疑义
- android 两个activity如何通信