关于PinnedHeaderExpandableListView使用的时候on a null object reference
2015-12-14 17:06
681 查看
天天在各种博客论坛学习大神们的代码,所以觉得也应该把自己的东西拿出来分享和提问,如果有用不用谢我,如果无用也不要骂我,谢谢各位
问题:今天要写一个分组的ListView带分组悬停效果的,看到这篇博文http://blog.csdn.net/h7870181/article/details/40400155,就直接用了。但是博主数据源用的是二维数组存放的,所以自己用List<List<Object>>的方式存放,结果使用的时候直接崩溃了,跟着log找到问题的地方
@Override
protected
void onLayout(boolean changed,
int left, int top,
int right,
int bottom) {
super.onLayout(changed, left, top, right, bottom);
final
long flatPostion = getExpandableListPosition(getFirstVisiblePosition());
final
int groupPos = ExpandableListView
.getPackedPositionGroup(flatPostion);
final
int childPos = ExpandableListView
.getPackedPositionChild(flatPostion);
int state = mAdapter.getHeaderState(groupPos, childPos); 这里报错 on a null object reference 大概是说引用了空的对象吧
if (mHeaderView !=
null && null != mAdapter
&& state != mOldState) {
mOldState = state;
mHeaderView.layout(0, 0,
mHeaderViewWidth, mHeaderViewHeight);
}
configureHeaderView(groupPos, childPos);
}
找不到问题出在哪里,不过后来把这里改成这样就可以,但是为什么会空值就不清楚了,知道的请留言说说,谢谢
@Override
protected
void onLayout(boolean changed,
int left, int top,
int right,
int bottom) {
super.onLayout(changed, left, top, right, bottom);
final
long flatPostion = getExpandableListPosition(getFirstVisiblePosition());
final
int groupPos = ExpandableListView
.getPackedPositionGroup(flatPostion);
final
int childPos = ExpandableListView
.getPackedPositionChild(flatPostion);
if (null !=
mAdapter) {
int state =
mAdapter.getHeaderState(groupPos, childPos);
if (mHeaderView !=
null && state != mOldState) {
mOldState = state;
mHeaderView.layout(0, 0,
mHeaderViewWidth, mHeaderViewHeight);
}
}
configureHeaderView(groupPos, childPos);
}
问题:今天要写一个分组的ListView带分组悬停效果的,看到这篇博文http://blog.csdn.net/h7870181/article/details/40400155,就直接用了。但是博主数据源用的是二维数组存放的,所以自己用List<List<Object>>的方式存放,结果使用的时候直接崩溃了,跟着log找到问题的地方
@Override
protected
void onLayout(boolean changed,
int left, int top,
int right,
int bottom) {
super.onLayout(changed, left, top, right, bottom);
final
long flatPostion = getExpandableListPosition(getFirstVisiblePosition());
final
int groupPos = ExpandableListView
.getPackedPositionGroup(flatPostion);
final
int childPos = ExpandableListView
.getPackedPositionChild(flatPostion);
int state = mAdapter.getHeaderState(groupPos, childPos); 这里报错 on a null object reference 大概是说引用了空的对象吧
if (mHeaderView !=
null && null != mAdapter
&& state != mOldState) {
mOldState = state;
mHeaderView.layout(0, 0,
mHeaderViewWidth, mHeaderViewHeight);
}
configureHeaderView(groupPos, childPos);
}
找不到问题出在哪里,不过后来把这里改成这样就可以,但是为什么会空值就不清楚了,知道的请留言说说,谢谢
@Override
protected
void onLayout(boolean changed,
int left, int top,
int right,
int bottom) {
super.onLayout(changed, left, top, right, bottom);
final
long flatPostion = getExpandableListPosition(getFirstVisiblePosition());
final
int groupPos = ExpandableListView
.getPackedPositionGroup(flatPostion);
final
int childPos = ExpandableListView
.getPackedPositionChild(flatPostion);
if (null !=
mAdapter) {
int state =
mAdapter.getHeaderState(groupPos, childPos);
if (mHeaderView !=
null && state != mOldState) {
mOldState = state;
mHeaderView.layout(0, 0,
mHeaderViewWidth, mHeaderViewHeight);
}
}
configureHeaderView(groupPos, childPos);
}
相关文章推荐
- Java Socket编程中使用ObjectOutputStream 和 ObjectInputStream 出现问题
- [转]在 Ubuntu 中使用 GNUstep 搭建 Objective-C 开发环境
- Objective-C 引用计数:不讲用法,只说原理
- 借鉴 C# 关于 LINQ 的设计思想用 C++ 11 来实现 LINQ to Object
- Objective-C AES128 Encrypt And Decrypt
- Android属性动画的学习_ObjectAnimator
- WaitForSingleObject 结束线程
- Objective-C Runtime
- 黑马程序员---Java基础---Object类
- android JSON获取值String无法转换成JSONObject
- IOS NSString 截取,objectAtIndex,rangeOfString,stringWithContentsOfFile,NSEnumerator
- html之object标签的classid收集
- Objective-C路成魔【18-复制对象】
- Objective-C 汤姆猫动画实现
- Objective-c语言_对可变字符串操作的常用方法
- Objective-c语言_对字符串操作的常用方法
- Objective-c语言_基本数据类型封装和拆包
- JSON中JObject和JArray,JValue序列化(Linq)
- foundation的使用——NSDate
- Java中Object类hashCode的实现