findViewById()返回null
来源:互联网 发布:淘宝店面装修视频教程 编辑:程序博客网 时间:2024/04/29 04:22
今天在重写BaseAdapter的getView()方法时,下面两行代码报空指针。
TextView tv_title = (TextView) findViewById(R.id.tv_title); ImageView iv_icon = (ImageView) findViewById(R.id.iv_icon);
后来查了一下,findViewById()返回null的话,有以下原因:
1.没有载入控件所在布局
这个不是我所产生的问题,在前面加上 View view = LayoutInflater.from(HomeActicity.this).inflate(R.layout.gridview_item,null);就可以
2.findViewById的完整写法是View.findViewById(),而不指定View时默认的是Context,因此当findViewById不是在context里执行时,要指定对应的View。
我就是这个问题,在findViewById()前面加上view就可以
0 0
- findViewById()返回 null
- findViewById返回null
- Andorid findViewById()返回Null
- findViewById()返回null
- findViewById返回Null 错误
- findViewById 返回null
- android findViewById 返回 null
- findViewById()返回 null
- findViewById返回Null
- findViewById返回Null
- findViewById返回null
- findViewById返回Null
- findViewById返回null
- findViewById返回为NULL
- findViewById 返回 null 问题
- findViewById()返回null
- findViewById返回Null
- 为什么findViewById会返回null
- javascript内建对象Date
- rtmp
- CSS3文本效果 、字体
- 关于手机网页边框很粗的解决方案
- [iOS imageView]headImage 异形图片的画法(小技巧记录)
- findViewById()返回null
- hdu4497(唯一分解+排列组合算组数)
- c++面向对象编程(二)重载
- html css控制浮动元素居中显示
- 9个基于Java的搜索引擎框架
- Android studio启动后卡在refreshing gradle project的一个解决办法 有意思哈哈
- ZTree学习(三),ztree树扩展
- 关于HtmlCxx对,C++ 解析,编辑,重新生成HTML的
- 主分区 拓展分区 逻辑分区的概念