我有一个活动,它会为一周中的每一天填充滚动视图,并使用视图寻呼机显示操作栏上的标签。每当我回到我已经访问过的标签时,我都会遇到类强制转换错误。 这是我的原木猫。有人可以告诉我为什么会引起这种异常。
08-23 05:01:50.589: E/AndroidRuntime(3836): FATAL EXCEPTION: main
08-23 05:01:50.589:E/AndroidRuntime(3836):java.lang.ClassCastException:android.view.AbsSavedState$1 cannot be cast to android.widget.CompoundButton$SavedState
08-23 05:01:50.589: E/AndroidRuntime(3836): at android.widget.CompoundButton.onRestoreInstanceState(CompoundButton.java:379)
08-23 05:01:50.589: E/AndroidRuntime(3836): at android.view.View.dispatchRestoreInstanceState(View.java:12284)
08-23 05:01:50.589: E/AndroidRuntime(3836): at android.view.ViewGroup.dispatchRestoreInstanceState(ViewGroup.java:2626)
08-23 05:01:50.589: E/AndroidRuntime(3836): at android.view.ViewGroup.dispatchRestoreInstanceState(ViewGroup.java:2626)
08-23 05:01:50.589: E/AndroidRuntime(3836): at android.view.ViewGroup.dispatchRestoreInstanceState(ViewGroup.java:2626)
08-23 05:01:50.589: E/AndroidRuntime(3836): at android.view.ViewGroup.dispatchRestoreInstanceState(ViewGroup.java:2626)
08-23 05:01:50.589: E/AndroidRuntime(3836): at android.view.ViewGroup.dispatchRestoreInstanceState(ViewGroup.java:2626)
08-23 05:01:50.589: E/AndroidRuntime(3836): at android.view.View.restoreHierarchyState(View.java:12262)
08-23 05:01:50.589: E/AndroidRuntime(3836): at android.support.v4.app.Fragment.restoreViewState(Fragment.java:425)
08-23 05:01:50.589: E/AndroidRuntime(3836): at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:949)
08-23 05:01:50.589: E/AndroidRuntime(3836): at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1104)
08-23 05:01:50.589: E/AndroidRuntime(3836): at android.support.v4.app.BackStackRecord.run(BackStackRecord.java:682)
08-23 05:01:50.589: E/AndroidRuntime(3836): at android.support.v4.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1460)
08-23 05:01:50.589: E/AndroidRuntime(3836): at android.support.v4.app.FragmentManagerImpl.executePendingTransactions(FragmentManager.java:472)
08-23 05:01:50.589: E/AndroidRuntime(3836): at android.support.v4.app.FragmentStatePagerAdapter.finishUpdate(FragmentStatePagerAdapter.java:163)
08-23 05:01:50.589: E/AndroidRuntime(3836): at android.support.v4.view.ViewPager.populate(ViewPager.java:1068)
08-23 05:01:50.589: E/AndroidRuntime(3836): at android.support.v4.view.ViewPager.setCurrentItemInternal(ViewPager.java:550)
08-23 05:01:50.589: E/AndroidRuntime(3836): at android.support.v4.view.ViewPager.setCurrentItemInternal(ViewPager.java:509)
08-23 05:01:50.589: E/AndroidRuntime(3836): at android.support.v4.view.ViewPager.setCurrentItem(ViewPager.java:490)
08-23 05:01:50.589: E/AndroidRuntime(3836): at com.example.attendogram.Start.onTabSelected(Start.java:195)
08-23 05:01:50.589: E/AndroidRuntime(3836): at com.android.internal.app.ActionBarImpl.selectTab(ActionBarImpl.java:572)
08-23 05:01:50.589: E/AndroidRuntime(3836): at com.android.internal.app.ActionBarImpl$TabImpl.select(ActionBarImpl.java:1098)
08-23 05:01:50.589: E/AndroidRuntime(3836): at com.android.internal.widget.ScrollingTabContainerView$TabClickListener.onClick(ScrollingTabContainerView.java:547)
08-23 05:01:50.589: E/AndroidRuntime(3836): at android.view.View.performClick(View.java:4240)
08-23 05:01:50.589: E/AndroidRuntime(3836): at android.view.View$PerformClick.run(View.java:17721)
08-23 05:01:50.589: E/AndroidRuntime(3836): at android.os.Handler.handleCallback(Handler.java:730)
08-23 05:01:50.589: E/AndroidRuntime(3836): at android.os.Handler.dispatchMessage(Handler.java:92)
08-23 05:01:50.589: E/AndroidRuntime(3836): at android.os.Looper.loop(Looper.java:137)
08-23 05:01:50.589: E/AndroidRuntime(3836): at android.app.ActivityThread.main(ActivityThread.java:5103)
08-23 05:01:50.589: E/AndroidRuntime(3836): at java.lang.reflect.Method.invokeNative(Native Method)
08-23 05:01:50.589: E/AndroidRuntime(3836): at java.lang.reflect.Method.invoke(Method.java:525)
08-23 05:01:50.589: E/AndroidRuntime(3836): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:737)
08-23 05:01:50.589: E/AndroidRuntime(3836): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
08-23 05:01:50.589: E/AndroidRuntime(3836): at dalvik.system.NativeStart.main(Native Method)
答案 0 :(得分:0)
我有类似的问题。在寻找答案时,我发现了这篇文章。 Unexplainable ClassCastException in android.widget.ProgressBar.onRestoreInstanceState
在我们所有的情况下,android.view.AbsSavedState $ 1都被强制转换为其他组件。
接受的答案说问题是应用程序正在重用ID。
“仔细检查您的应用程序是否在两个不同的地方重复使用相同的ID”
如果您使用的是eclipse,Lint工具可以帮助您追踪重复的ID。 。我希望这有帮助。