AbsSpinner$SavedState 无法转换为 AbsListView$SavedState

发布于 2024-11-25 22:42:54 字数 3928 浏览 0 评论 0原文

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

恢复后,图库可以很好地读取列表的信息。这是无法读取图库保存状态的列表。我在下面附上了堆栈跟踪,尽管它告诉我的信息很少。您能提供的任何光芒都会有所帮助!顺便说一句,目标 api 是 3.0。

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

my problem, I believe, is that I have a gallery in portrait mode and a listview in landscape mode. They're both using the same adapter and in the same view. However, on orientation change, the listview attempts to read the information from the gallery and the program crashes.

The gallery reads the list's information fine when it restores. It is the list that cannot read the gallery's save state. I've attached the stack trace below though it tells me very little. Any light that you could shed would be helpful! Target api is 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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

不喜欢何必死缠烂打 2024-12-02 22:42:54

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

Presumably, you have both the Gallery and the ListView named the same. You cannot safely do that, as you have discovered. Change one of their names to something distinct. You will also need to override onSaveInstanceState() and onRestoreInstanceState() to convert between the two instance states yourself (in addition to chaining to the superclass from each of those methods to inherit the default behavior).

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文