AbsSpinner $ SavedState无法强制转换为AbsListView $ SavedState

时间:2011-07-22 21:08:05

标签: android orientation fragment

我相信,我的问题是,我在纵向模式下有一个画廊,在横向模式下有一个列表视图。他们都使用相同的适配器并在同一视图中。但是,在方向更改时,列表视图会尝试从库中读取信息并且程序崩溃。

图库在恢复时会读取列表的信息。列表无法读取图库的保存状态。我已经附上了下面的堆栈跟踪,虽然它告诉我很少。任何你可以放下的灯都会有帮助!目标api是3.0 btw。

07-22 20:58:35.660: ERROR/AndroidRuntime(2191): FATAL EXCEPTION: main
07-22 20:58:35.660: ERROR/AndroidRuntime(2191): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.awesome.OASAC/com.awesome.OASAC.OASACActivity}: java.lang.ClassCastException: android.widget.AbsSpinner$SavedState cannot be cast to android.widget.AbsListView$SavedState
07-22 20:58:35.660: ERROR/AndroidRuntime(2191):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1736)
07-22 20:58:35.660: ERROR/AndroidRuntime(2191):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1752)
07-22 20:58:35.660: ERROR/AndroidRuntime(2191):     at android.app.ActivityThread.handleRelaunchActivity(ActivityThread.java:3096)
07-22 20:58:35.660: ERROR/AndroidRuntime(2191):     at android.app.ActivityThread.access$1600(ActivityThread.java:123)
07-22 20:58:35.660: ERROR/AndroidRuntime(2191):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:997)
07-22 20:58:35.660: ERROR/AndroidRuntime(2191):     at android.os.Handler.dispatchMessage(Handler.java:99)
07-22 20:58:35.660: ERROR/AndroidRuntime(2191):     at android.os.Looper.loop(Looper.java:126)
07-22 20:58:35.660: ERROR/AndroidRuntime(2191):     at android.app.ActivityThread.main(ActivityThread.java:3997)
07-22 20:58:35.660: ERROR/AndroidRuntime(2191):     at java.lang.reflect.Method.invokeNative(Native Method)
07-22 20:58:35.660: ERROR/AndroidRuntime(2191):     at java.lang.reflect.Method.invoke(Method.java:491)
07-22 20:58:35.660: ERROR/AndroidRuntime(2191):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:841)
07-22 20:58:35.660: ERROR/AndroidRuntime(2191):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:599)
07-22 20:58:35.660: ERROR/AndroidRuntime(2191):     at dalvik.system.NativeStart.main(Native Method)
07-22 20:58:35.660: ERROR/AndroidRuntime(2191): Caused by: java.lang.ClassCastException: android.widget.AbsSpinner$SavedState cannot be cast to android.widget.AbsListView$SavedState
07-22 20:58:35.660: ERROR/AndroidRuntime(2191):     at android.widget.AbsListView.onRestoreInstanceState(AbsListView.java:1520)
07-22 20:58:35.660: ERROR/AndroidRuntime(2191):     at android.view.View.dispatchRestoreInstanceState(View.java:8101)
07-22 20:58:35.660: ERROR/AndroidRuntime(2191):     at android.view.ViewGroup.dispatchThawSelfOnly(ViewGroup.java:1972)
07-22 20:58:35.660: ERROR/AndroidRuntime(2191):     at android.widget.AdapterView.dispatchRestoreInstanceState(AdapterView.java:766)
07-22 20:58:35.660: ERROR/AndroidRuntime(2191):     at android.view.ViewGroup.dispatchRestoreInstanceState(ViewGroup.java:1958)
07-22 20:58:35.660: ERROR/AndroidRuntime(2191):     at android.view.View.restoreHierarchyState(View.java:8080)
07-22 20:58:35.660: ERROR/AndroidRuntime(2191):     at android.app.Fragment.restoreViewState(Fragment.java:516)
07-22 20:58:35.660: ERROR/AndroidRuntime(2191):     at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:742)
07-22 20:58:35.660: ERROR/AndroidRuntime(2191):     at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:921)
07-22 20:58:35.660: ERROR/AndroidRuntime(2191):     at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:904)
07-22 20:58:35.660: ERROR/AndroidRuntime(2191):     at android.app.FragmentManagerImpl.dispatchStart(FragmentManager.java:1579)
07-22 20:58:35.660: ERROR/AndroidRuntime(2191):     at android.app.Activity.performStart(Activity.java:4320)
07-22 20:58:35.660: ERROR/AndroidRuntime(2191):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1709)
07-22 20:58:35.660: ERROR/AndroidRuntime(2191):     ... 12 more

1 个答案:

答案 0 :(得分:3)

据推测,您GalleryListView的名称相同。正如您所发现的那样,您无法安全地做到这一点。将其中一个名称更改为不同的名称。您还需要覆盖onSaveInstanceState()onRestoreInstanceState()以自己在两个实例状态之间进行转换(除了从每个方法链接到超类以继承默认行为)。