当前位置: 首页 > 工具软件 > Lang switcher > 使用案例 >

java.lang.IllegalStateException: Can't change tag of fragment异常解决

东方河
2023-12-01

Process: learnknow.ibn.com.lezhiteacherpad, PID: 21844
    java.lang.IllegalStateException: Can't change tag of fragment CompositionDataAnalysisFragment{16ad829a id=0x7f090163 android:switcher:2131296611:0}: was android:switcher:2131296611:0 now android:switcher:2131296611:1
        at android.support.v4.app.BackStackRecord.doAddOp(BackStackRecord.java:409)
        at android.support.v4.app.BackStackRecord.add(BackStackRecord.java:391)
        at android.support.v4.app.FragmentPagerAdapter.instantiateItem(FragmentPagerAdapter.java:107)
        at learnknow.ibn.com.lezhiteacherpad.compositionTask.adapter.MyPagerAdapter.instantiateItem(MyPagerAdapter.java:44)
        at android.support.v4.view.ViewPager.addNewItem(ViewPager.java:1010)
        at android.support.v4.view.ViewPager.populate(ViewPager.java:1224)
        at android.support.v4.view.ViewPager.populate(ViewPager.java:1092)
        at android.support.v4.view.ViewPager.onMeasure(ViewPager.java:1622)
        at android.view.View.measure(View.java:17553)
        at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5537)
        at android.support.design.widget.CoordinatorLayout.onMeasureChild(CoordinatorLayout.java:733)
        at android.support.design.widget.HeaderScrollingViewBehavior.onMeasureChild(HeaderScrollingViewBehavior.java:95)
        at android.support.design.widget.AppBarLayout$ScrollingViewBehavior.onMeasureChild(AppBarLayout.java:1556)
        at android.support.design.widget.CoordinatorLayout.onMeasure(CoordinatorLayout.java:803)
        at android.view.View.measure(View.java:17553)
        at android.support.v4.view.ViewPager.onMeasure(ViewPager.java:1638)
        at android.view.View.measure(View.java:17553)
        at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5537)
        at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1436)
        at android.widget.LinearLayout.measureVertical(LinearLayout.java:722)
        at android.widget.LinearLayout.onMeasure(LinearLayout.java:613)
        at android.view.View.measure(View.java:17553)
        at android.widget.LinearLayout.measureHorizontal(LinearLayout.java:1063)
        at android.widget.LinearLayout.onMeasure(LinearLayout.java:615)
        at android.view.View.measure(View.java:17553)
        at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5537)
        at android.widget.FrameLayout.onMeasure(FrameLayout.java:436)
        at android.view.View.measure(View.java:17553)
        at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5537)
        at android.widget.FrameLayout.onMeasure(FrameLayout.java:436)
        at android.view.View.measure(View.java:17553)
        at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5537)
        at android.widget.FrameLayout.onMeasure(FrameLayout.java:436)
        at android.view.View.measure(View.java:17553)
        at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5537)
        at android.widget.FrameLayout.onMeasure(FrameLayout.java:436)
        at android.support.v7.widget.ContentFrameLayout.onMeasure(ContentFrameLayout.java:143)
        at android.view.View.measure(View.java:17553)
        at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5537)
        at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1436)
        at android.widget.LinearLayout.measureVertical(LinearLayout.java:722)
        at android.widget.LinearLayout.onMeasure(LinearLayout.java:613)
        at android.view.View.measure(View.java:17553)
        at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5537)
        at android.widget.FrameLayout.onMeasure(FrameLayout.java:436)
        at android.view.View.measure(View.java:17553)
        at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5537)
        at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1436)
        at android.widget.LinearLayout.measureVertical(LinearLayout.java:722)
        at android.widget.LinearLayout.onMeasure(LinearLayout.java:613)
        at android.view.View.measure(View.java:17553)
        at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5537)
        at android.widget.FrameLayout.onMeasure(FrameLayout.java:436)
        at com.android.internal.policy.impl.PhoneWindow$DecorView.onMeasure(PhoneWindow.java:2631)

 

出现这个bug的原因是因为同一个fragment对象同时添加到了碎片集合fragmentList中,所以导致pageadapter抛出无法识别切换fragment的异常,同一个fragment的类可以创建出很多个实例添加到fragmentList中给adapter,但不能一个集合筛多个这一个实例对象,这就是问题出现的原因

 

 

 类似资料: