造成这种结果一般有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
- !使用JDNI时,报 Cannot create JDBC driver of class '' for connect URL 'null'
- null id in com.bsw.gms.hibernate.pojo.Score entry (don't flush the Session after an exception occurs,该怎么解决
- org.hibernate.PropertyAccessException: Null value was assigned to a property of解决办法
- android 读取byte[]中的元素解决方案
- android 标题栏兑现方式
- android 中Activity向BroadcastReceiver发送数据,该怎么解决
- Android 4.0 为什么模拟器老是提示小弟我谷歌拼音输入法已停止
- null == a 跟 a == null 的区别
- android:getSharedPreferences() 这是哪个类的方法解决思路
- android 怎么判断一个程序是否联网
- android RadioButton如何设置默认选中
- android 怎么重新设置锚点
- android 图片对象获取的有关问题
- android 关于服务连接的疑义
- android 怎么实现对view的放大和缩小
- android ID,该如何处理
- 准备复习2-3个月,看java+android,请问有经验者,怎么看效果最好》
- android UI线程与AsyncTask的有关问题
- android(java) 中文乱码的有关问题
- null!= xxx 跟 xxx!=null有什么区别
- 下传组件老说PostedFile = null
- 行15: 没法获取属性“appendChild”的值: 对象为 null 或未定义
- cid = (string.IsNullOrEmpty(typeId) ? null : ( Convert.ToInt32( typeId)) ) 有解决方案
- 存储过程调用 is not null 判断不成功解决思路
- MVC3.0 Model主外键关联有关问题 设置foreignkey后取不到数据,null
- 外网,访问数据库揭示 用户'(null)' 登录失败。原因: 未与信任 SQL Server 连接相关联
- select * from authors where au_id is not null 存储过程怎么写
- Cache.Insert(key,key,null,DateTime.MaxValue,TimeSpan.Zero,NotRemovable,null),有2个参数不太懂解决办法
- UpdatePanel装用户控件注册了脚本了但是在隐藏文件提示:"Microsoft JScript 运行时异常: 'null' 为空或不是对象"