java.lang.IllegalArgumentException: Wrong state class, expecting View State but received

今天在开发过程中遇到了以下的错误:
java.lang.IllegalArgumentException: Wrong state class, expecting View State but received class android.support.v7.widget.RecyclerView$SavedState instead. This usually happens when two views of different type have the same id in the same hierarchy. This view’s id is id/dynamic_rv. Make sure other views do not use the same id.
因为我的首页是用viewpager结合fragment做的几个可以左右滑动的TAB页面,A页面又用了github上开源的下拉刷新控件,当离开A页面后再从其他页面返回时,便出现了以上错误,大致意思就是layout的ID重复了,至于为什么会重复,就没有深入了解下去了。
解决方式是找到自定义控件的类,比如我的是这样的

        public class NRecyclerView extends BaseLayout {

    private RecyclerView.LayoutManager layoutManager;
    private InnerAdapter adapter;
    private final RecyclerView.AdapterDataObserver mDataObserver = new DataObserver();

    public NRecyclerView(Context context, AttributeSet attrs) {
        super(context, attrs);
    }

    private ViewGroup AdtureView;
    private ViewGroup BottomView;
    ........

在此控件中重写onRestoreInstanceState方法,

    @Override
    protected void onRestoreInstanceState(Parcelable state) {
        try {
            super.onRestoreInstanceState(state);
        }catch (Exception e) {}
        state=null;
    }

解决问题。

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章