java.lang.IllegalArgumentException: Wrong state classs

出处:http://blog.csdn.net/yilip/article/details/44345655

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;
      }

     再次运行程序,问题得到解决


  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值