我通过 Acra 收到了 Android 应用程序的错误报告。在堆栈跟踪中我的代码中没有对行号的引用。我怎么知道问题出在我的代码上?谁能帮助我。
堆栈跟踪:
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.itse.htsurvey/com.itse.htsurvey.Question2Page2Activity}: java.lang.ClassCastException: android.widget.CompoundButton$SavedState cannot be cast to android.widget.AbsSpinner$SavedState
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1815)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1831)
at android.app.ActivityThread.handleRelaunchActivity(ActivityThread.java:3188)
at android.app.ActivityThread.access$600(ActivityThread.java:122)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1028)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:132)
at android.app.ActivityThread.main(ActivityThread.java:4123)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:491)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:841)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:599)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.ClassCastException: android.widget.CompoundButton$SavedState cannot be cast to android.widget.AbsSpinner$SavedState
at android.widget.AbsSpinner.onRestoreInstanceState(AbsSpinner.java:421)
at android.view.View.dispatchRestoreInstanceState(View.java:8316)
at android.view.ViewGroup.dispatchThawSelfOnly(ViewGroup.java:2038)
at android.widget.AdapterView.dispatchRestoreInstanceState(AdapterView.java:766)
at android.view.ViewGroup.dispatchRestoreInstanceState(ViewGroup.java:2024)
at android.view.ViewGroup.dispatchRestoreInstanceState(ViewGroup.java:2024)
at android.view.ViewGroup.dispatchRestoreInstanceState(ViewGroup.java:2024)
at android.view.ViewGroup.dispatchRestoreInstanceState(ViewGroup.java:2024)
at android.view.ViewGroup.dispatchRestoreInstanceState(ViewGroup.java:2024)
at android.view.ViewGroup.dispatchRestoreInstanceState(ViewGroup.java:2024)
at android.view.View.restoreHierarchyState(View.java:8295)
at com.android.internal.policy.impl.PhoneWindow.restoreHierarchyState(PhoneWindow.java:1489)
at android.app.Activity.onRestoreInstanceState(Activity.java:898)
at android.app.Activity.performRestoreInstanceState(Activity.java:870)
at android.app.Instrumentation.callActivityOnRestoreInstanceState(Instrumentation.java:1099)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1793)
... 12 more
java.lang.ClassCastException: android.widget.CompoundButton$SavedState cannot be cast to android.widget.AbsSpinner$SavedState
at android.widget.AbsSpinner.onRestoreInstanceState(AbsSpinner.java:421)
at android.view.View.dispatchRestoreInstanceState(View.java:8316)
at android.view.ViewGroup.dispatchThawSelfOnly(ViewGroup.java:2038)
at android.widget.AdapterView.dispatchRestoreInstanceState(AdapterView.java:766)
at android.view.ViewGroup.dispatchRestoreInstanceState(ViewGroup.java:2024)
at android.view.ViewGroup.dispatchRestoreInstanceState(ViewGroup.java:2024)
at android.view.ViewGroup.dispatchRestoreInstanceState(ViewGroup.java:2024)
at android.view.ViewGroup.dispatchRestoreInstanceState(ViewGroup.java:2024)
at android.view.ViewGroup.dispatchRestoreInstanceState(ViewGroup.java:2024)
at android.view.ViewGroup.dispatchRestoreInstanceState(ViewGroup.java:2024)
at android.view.View.restoreHierarchyState(View.java:8295)
at com.android.internal.policy.impl.PhoneWindow.restoreHierarchyState(PhoneWindow.java:1489)
at android.app.Activity.onRestoreInstanceState(Activity.java:898)
at android.app.Activity.performRestoreInstanceState(Activity.java:870)
at android.app.Instrumentation.callActivityOnRestoreInstanceState(Instrumentation.java:1099)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1793)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1831)
at android.app.ActivityThread.handleRelaunchActivity(ActivityThread.java:3188)
at android.app.ActivityThread.access$600(ActivityThread.java:122)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1028)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:132)
at android.app.ActivityThread.main(ActivityThread.java:4123)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:491)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:841)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:599)
at dalvik.system.NativeStart.main(Native Method)
我的代码 com.itse.htsurvey.Question2Page2Activity:http ://pastebin.com/gPYyZ0GH
编辑 1:更多信息 - 我认为这可能是因为小部件 ID 冲突。savedState 部分表示这发生在 Activity 重新创建之后?此布局由动态添加的视图/布局组成,它们在运行时被赋予 id。
编辑2:只是为了确认在所有测试中,这是我第一次收到这个错误。我无法重现它。
编辑 3:当我更改设备的方向时,我能够重现该错误。那我该如何解决这个问题?