我在Crashlytics上看到了很多次以下错误:
Caused by java.lang.ClassCastException: android.view.AbsSavedState$1 cannot be cast to android.widget.CompoundButton$SavedState
at android.widget.CompoundButton.onRestoreInstanceState(CompoundButton.java)
at android.view.View.dispatchRestoreInstanceState(View.java)
at android.view.ViewGroup.dispatchRestoreInstanceState(ViewGroup.java)
at android.view.ViewGroup.dispatchRestoreInstanceState(ViewGroup.java)
at android.view.ViewGroup.dispatchRestoreInstanceState(ViewGroup.java)
at android.view.ViewGroup.dispatchRestoreInstanceState(ViewGroup.java)
at android.view.ViewGroup.dispatchRestoreInstanceState(ViewGroup.java)
at android.view.ViewGroup.dispatchRestoreInstanceState(ViewGroup.java)
at android.view.View.restoreHierarchyState(View.java)
at android.support.v4.app.Fragment.restoreViewState(Fragment.java:494)
at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1486)
at android.support.v4.app.FragmentManagerImpl.moveFragmentToExpectedState(FragmentManager.java:1784)
at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1852)
at android.support.v4.app.FragmentManagerImpl.dispatchStateChange(FragmentManager.java:3269)
at android.support.v4.app.FragmentManagerImpl.dispatchActivityCreated(FragmentManager.java:3229)
at android.support.v4.app.Fragment.performActivityCreated(Fragment.java:2466)
at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1483)
at android.support.v4.app.FragmentManagerImpl.moveFragmentToExpectedState(FragmentManager.java:1784)
at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1852)
at android.support.v4.app.FragmentManagerImpl.dispatchStateChange(FragmentManager.java:3269)
at android.support.v4.app.FragmentManagerImpl.dispatchActivityCreated(FragmentManager.java:3229)
at android.support.v4.app.FragmentController.dispatchActivityCreated(FragmentController.java:201)
at android.support.v4.app.FragmentActivity.onStart(FragmentActivity.java:620)
at android.support.v7.app.AppCompatActivity.onStart(AppCompatActivity.java:178)
at android.app.Instrumentation.callActivityOnStart(Instrumentation.java)
at android.app.Activity.performStart(Activity.java)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java)
at android.app.ActivityThread.access$900(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java)
at android.os.Handler.dispatchMessage(Handler.java)
at android.os.Looper.loop(Looper.java)
at android.app.ActivityThread.main(ActivityThread.java)
at java.lang.reflect.Method.invoke(Method.java)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java)
然而,这个堆栈跟踪并没有涉及到我的代码库,因为异常是在平台级别抛出的。
从我所阅读的内容来看,这可能与重复的ID有关,但是我在我的代码中找不到任何重复的ID,请问有什么办法可以调试这个问题吗?
我还尝试在开发者选项中启用“不保留活动”以强制进行实例恢复,但我无法手动重现崩溃。
onStart
中恢复了一个片段。您是否有包含RadioButton
、Checkbox
、Switch
、ToggleButton
的片段?如果有,请尝试在那里设置断点,并在Watches 窗口
中检查是否将它们转换错误。 - deadfishView
子类,它们派生自CompoundButton
(或其子类)? - Ben P.