当我开始编写嵌套片段时,遇到了意外问题。当应用程序被Android杀死时,例如当有少量可用RAM时,应用程序将在恢复它后引发以下异常。

E/Parcel: Class not found when unmarshalling: android.support.design.widget.CoordinatorLayout$SavedState
      java.lang.ClassNotFoundException: android.support.design.widget.CoordinatorLayout$SavedState
          at java.lang.Class.classForName(Native Method)
          at java.lang.Class.forName(Class.java:453)
          at android.os.Parcel.readParcelableCreator(Parcel.java:2888)
          at android.os.Parcel.readParcelable(Parcel.java:2842)
          at android.os.Parcel.readValue(Parcel.java:2745)
          at android.os.Parcel.readSparseArrayInternal(Parcel.java:3195)
          at android.os.Parcel.readSparseArray(Parcel.java:2407)
          at android.os.Parcel.readValue(Parcel.java:2802)
          at android.os.Parcel.readArrayMapInternal(Parcel.java:3114)
          at android.os.BaseBundle.initializeFromParcelLocked(BaseBundle.java:273)
          at android.os.BaseBundle.unparcel(BaseBundle.java:226)
          at android.os.BaseBundle.putBoolean(BaseBundle.java:532)
          at android.support.v4.app.Fragment.setUserVisibleHint(Fragment.java:960)
          at android.support.v4.app.FragmentStatePagerAdapter.instantiateItem(FragmentStatePagerAdapter.java:121)
          at android.support.v4.view.ViewPager.addNewItem(ViewPager.java:1004)
          at android.support.v4.view.ViewPager.populate(ViewPager.java:1186)
          at android.support.v4.view.ViewPager.populate(ViewPager.java:1086)
          at android.support.v4.view.ViewPager$3.run(ViewPager.java:267)
          at android.view.Choreographer$CallbackRecord.run(Choreographer.java:911)
          at android.view.Choreographer.doCallbacks(Choreographer.java:723)
          at android.view.Choreographer.doFrame(Choreographer.java:655)
          at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:897)
          at android.os.Handler.handleCallback(Handler.java:790)
          at android.os.Handler.dispatchMessage(Handler.java:99)
          at android.os.Looper.loop(Looper.java:164)
          at android.app.ActivityThread.main(ActivityThread.java:6494)
          at java.lang.reflect.Method.invoke(Native Method)
          at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:438)
          at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:807)
       Caused by: java.lang.ClassNotFoundException: android.support.design.widget.CoordinatorLayout$SavedState
          at java.lang.Class.classForName(Native Method)
          at java.lang.BootClassLoader.findClass(ClassLoader.java:1355)
          at java.lang.BootClassLoader.loadClass(ClassLoader.java:1415)
          at java.lang.ClassLoader.loadClass(ClassLoader.java:312)
          at java.lang.Class.classForName(Native Method) 
          at java.lang.Class.forName(Class.java:453) 
          at android.os.Parcel.readParcelableCreator(Parcel.java:2888) 
          at android.os.Parcel.readParcelable(Parcel.java:2842) 
          at android.os.Parcel.readValue(Parcel.java:2745) 
          at android.os.Parcel.readSparseArrayInternal(Parcel.java:3195) 
          at android.os.Parcel.readSparseArray(Parcel.java:2407) 
          at android.os.Parcel.readValue(Parcel.java:2802) 
          at android.os.Parcel.readArrayMapInternal(Parcel.java:3114) 
          at android.os.BaseBundle.initializeFromParcelLocked(BaseBundle.java:273) 
          at android.os.BaseBundle.unparcel(BaseBundle.java:226) 
          at android.os.BaseBundle.putBoolean(BaseBundle.java:532) 
          at android.support.v4.app.Fragment.setUserVisibleHint(Fragment.java:960) 
          at android.support.v4.app.FragmentStatePagerAdapter.instantiateItem(FragmentStatePagerAdapter.java:121) 
          at android.support.v4.view.ViewPager.addNewItem(ViewPager.java:1004) 
          at android.support.v4.view.ViewPager.populate(ViewPager.java:1186) 
          at android.support.v4.view.ViewPager.populate(ViewPager.java:1086) 
          at android.support.v4.view.ViewPager$3.run(ViewPager.java:267) 
          at android.view.Choreographer$CallbackRecord.run(Choreographer.java:911) 
          at android.view.Choreographer.doCallbacks(Choreographer.java:723) 
          at android.view.Choreographer.doFrame(Choreographer.java:655) 
          at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:897) 
          at android.os.Handler.handleCallback(Handler.java:790) 
          at android.os.Handler.dispatchMessage(Handler.java:99) 
          at android.os.Looper.loop(Looper.java:164) 
          at android.app.ActivityThread.main(ActivityThread.java:6494) 
          at java.lang.reflect.Method.invoke(Native Method) 
          at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:438) 
          at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:807) 
       Caused by: java.lang.NoClassDefFoundError: Class not found using the boot class loader; no stack trace available

android.os.BadParcelableException: ClassNotFoundException when unmarshalling: android.support.design.widget.CoordinatorLayout$SavedState
                  at android.os.Parcel.readParcelableCreator(Parcel.java:2916)
                  at android.os.Parcel.readParcelable(Parcel.java:2842)
                  at android.os.Parcel.readValue(Parcel.java:2745)
                  at android.os.Parcel.readSparseArrayInternal(Parcel.java:3195)
                  at android.os.Parcel.readSparseArray(Parcel.java:2407)
                  at android.os.Parcel.readValue(Parcel.java:2802)
                  at android.os.Parcel.readArrayMapInternal(Parcel.java:3114)
                  at android.os.BaseBundle.initializeFromParcelLocked(BaseBundle.java:273)
                  at android.os.BaseBundle.unparcel(BaseBundle.java:226)
                  at android.os.BaseBundle.putBoolean(BaseBundle.java:532)
                  at android.support.v4.app.Fragment.setUserVisibleHint(Fragment.java:960)
                  at android.support.v4.app.FragmentStatePagerAdapter.instantiateItem(FragmentStatePagerAdapter.java:121)
                  at android.support.v4.view.ViewPager.addNewItem(ViewPager.java:1004)
                  at android.support.v4.view.ViewPager.populate(ViewPager.java:1186)
                  at android.support.v4.view.ViewPager.populate(ViewPager.java:1086)
                  at android.support.v4.view.ViewPager$3.run(ViewPager.java:267)
                  at android.view.Choreographer$CallbackRecord.run(Choreographer.java:911)
                  at android.view.Choreographer.doCallbacks(Choreographer.java:723)
                  at android.view.Choreographer.doFrame(Choreographer.java:655)
                  at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:897)
                  at android.os.Handler.handleCallback(Handler.java:790)
                  at android.os.Handler.dispatchMessage(Handler.java:99)
                  at android.os.Looper.loop(Looper.java:164)
                  at android.app.ActivityThread.main(ActivityThread.java:6494)
                  at java.lang.reflect.Method.invoke(Native Method)
                  at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:438)
                  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:807)


仅当在XML android ID中分配了标签片段中的RecyclerView或CoordinatorLayout时,才会发生此错误。
为了识别错误,我编写了一个应用程序,并在其中复制了该错误。
https://github.com/RicomenPL/SampleBPE

如何复制它?


在智能手机或仿真器的开发选项中启用“不要保留活动”
打开SampleBPE应用程序
向左或向右移动至标签
现在您必须按Home键离开
使用最近的应用程序密钥再次输入
向左或向右移动标签会导致错误

最佳答案

当我将支持库降级到26.1.0版时,此问题已解决。这是一个临时解决方案,可以避免此问题。我希望在版本28中可以解决此问题。

07-24 09:20