我遇到的异常只发生在我启动应用程序时的5-10%。该活动主要包含一个ScrollView
,其中约有20张“卡”垂直排列(如列表)。每张“卡片”都是Fragment
,我只需构建20次并添加到LinearLayout
内的ScrollView
容器中。
我启动时,我的应用程序有时会立即崩溃...
07-25 11:14:04.211: E/AndroidRuntime(21490): Caused by: java.lang.IllegalArgumentException: Wrong state class, expecting View State but received class android.widget.ProgressBar$SavedState instead. This usually happens when two views of different type have the same id in the same hierarchy. This view's id is id/home_page_category_image. Make sure other views do not use the same id.
07-25 11:14:04.211: E/AndroidRuntime(21490): at android.view.View.onRestoreInstanceState(View.java:9990)
07-25 11:14:04.211: E/AndroidRuntime(21490): at android.view.View.dispatchRestoreInstanceState(View.java:9966)
07-25 11:14:04.211: E/AndroidRuntime(21490): at android.view.ViewGroup.dispatchRestoreInstanceState(ViewGroup.java:2622)
07-25 11:14:04.211: E/AndroidRuntime(21490): at android.view.ViewGroup.dispatchRestoreInstanceState(ViewGroup.java:2628)
07-25 11:14:04.211: E/AndroidRuntime(21490): at android.view.ViewGroup.dispatchRestoreInstanceState(ViewGroup.java:2628)
07-25 11:14:04.211: E/AndroidRuntime(21490): at android.view.ViewGroup.dispatchRestoreInstanceState(ViewGroup.java:2628)
07-25 11:14:04.211: E/AndroidRuntime(21490): at android.view.ViewGroup.dispatchRestoreInstanceState(ViewGroup.java:2628)
07-25 11:14:04.211: E/AndroidRuntime(21490): at android.view.ViewGroup.dispatchRestoreInstanceState(ViewGroup.java:2628)
07-25 11:14:04.211: E/AndroidRuntime(21490): at android.view.View.restoreHierarchyState(View.java:9944)
07-25 11:14:04.211: E/AndroidRuntime(21490): at android.app.Fragment.restoreViewState(Fragment.java:685)
07-25 11:14:04.211: E/AndroidRuntime(21490): at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:855)
07-25 11:14:04.211: E/AndroidRuntime(21490): at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:1034)
07-25 11:14:04.211: E/AndroidRuntime(21490): at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:1016)
07-25 11:14:04.211: E/AndroidRuntime(21490): at android.app.FragmentManagerImpl.dispatchActivityCreated(FragmentManager.java:1768)
07-25 11:14:04.211: E/AndroidRuntime(21490): at android.app.Activity.performCreate(Activity.java:4546)
07-25 11:14:04.211: E/AndroidRuntime(21490): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1071)
07-25 11:14:04.211: E/AndroidRuntime(21490): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2181)
07-25 11:14:04.211: E/AndroidRuntime(21490): ... 11 more
确实,每张“卡片”中的View
之一都有一个id标记home_page_category_image
。我环顾四周,大多数人得到这个错误往往与方向变化有关。我在清单中指定此活动只能处于纵向状态。更进一步,更奇怪的是,这种例外只发生在5-10%的时间。
有谁知道造成这种情况的原因或如何解决?