java.lang.IllegalArgumentException: Wrong state classs
2015-08-04 16:30
465 查看
出处:/article/8501538.html
java.lang.IllegalArgumentException: Wrong state class, expecting View State but received class cn.etouch.ecalendar.waterfallview.StaggeredGridView$GridListSavedState
instead. This usually happens when two views of different type have the same id in the same hierarchy. This view's id is id/refresh_gridView. Make sure other views do not use the same id.
按照Log的提示,是id起了冲突。但是我经过仔细查看XML布局文件,并没有起冲突的ID,事实上,在xml布局文件中经常有重名的id。网上还有一些说通过clean项目,这个也解决不了问题。
我遇到的情形是:FragmentA 中包括FragmentA1,FragmentA2,FragmentA3,FragementA3中有一个自定义的GridView,当A1,A2和A3之间切换时,程序就会崩溃,并报上述的错误。
id相同?确实可能是ID相同。因为,当A1,A2和A3切换的时候,将A3的gridView状态保存了,当然id也保存下来了。下次再切换到A3就可能出现id相同的情形。(不知道理解的对不对?)
这时候需要重写GridView中的onRestoreInstanceState函数:
默认:
@Override
protected void onRestoreInstanceState(Parcelable state) {
super.onRestoreInstanceState(state); }
修改为:
@Override
protected void onRestoreInstanceState(Parcelable state) {
try {
super.onRestoreInstanceState(state);
}catch (Exception e) {}
state=null;
}
再次运行程序,问题得到解决
java.lang.IllegalArgumentException: Wrong state class, expecting View State but received class cn.etouch.ecalendar.waterfallview.StaggeredGridView$GridListSavedState
instead. This usually happens when two views of different type have the same id in the same hierarchy. This view's id is id/refresh_gridView. Make sure other views do not use the same id.
按照Log的提示,是id起了冲突。但是我经过仔细查看XML布局文件,并没有起冲突的ID,事实上,在xml布局文件中经常有重名的id。网上还有一些说通过clean项目,这个也解决不了问题。
我遇到的情形是:FragmentA 中包括FragmentA1,FragmentA2,FragmentA3,FragementA3中有一个自定义的GridView,当A1,A2和A3之间切换时,程序就会崩溃,并报上述的错误。
id相同?确实可能是ID相同。因为,当A1,A2和A3切换的时候,将A3的gridView状态保存了,当然id也保存下来了。下次再切换到A3就可能出现id相同的情形。(不知道理解的对不对?)
这时候需要重写GridView中的onRestoreInstanceState函数:
默认:
@Override
protected void onRestoreInstanceState(Parcelable state) {
super.onRestoreInstanceState(state); }
修改为:
@Override
protected void onRestoreInstanceState(Parcelable state) {
try {
super.onRestoreInstanceState(state);
}catch (Exception e) {}
state=null;
}
再次运行程序,问题得到解决
相关文章推荐
- spring中的小知识点
- 10+ Best Websites for Java Developers
- Could not publish to the server.java.lang.NullPointerException
- Lowest Common Ancestor of a Binary Search Tree
- MapReduce进一步了解(二)——序列化
- myeclipse的注解和编码设置
- PyDev+eclipse
- java中使用OpenSSL生成的RSA公私钥进行数据加解密
- Java中byte与16进制字符串的互换原理
- Java中byte与16进制字符串的互换原理 分类: Java 2015-08-04 16:19 1人阅读 评论(0) 收藏
- VB加密算法改成java
- Java内部类
- hdu1285 拓扑排序 java实现
- SpringAOP拦截Controller,Service实现日志管理(自定义注解的方式)
- Java类型转换实例
- Java类型转换实例 分类: Java 2015-08-04 16:13 10人阅读 评论(0) 收藏
- Spring知识点小结
- js前台分页显示后端JAVA数据响应
- JavaWeb用户登陆--项目环境的搭建
- java web实现分页显示数据