AbsSpinner$SavedState 无法转换为 AbsListView$SavedState
我相信我的问题是我有一个纵向模式的画廊和横向模式的列表视图。它们都使用相同的适配器并处于相同的视图中。但是,在方向更改时,列表视图尝试从图库中读取信息,并且程序崩溃。
恢复后,图库可以很好地读取列表的信息。这是无法读取图库保存状态的列表。我在下面附上了堆栈跟踪,尽管它告诉我的信息很少。您能提供的任何光芒都会有所帮助!顺便说一句,目标 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
据推测,您的
Gallery
和ListView
名称相同。正如您所发现的,您无法安全地这样做。将其中一个名字更改为不同的名称。您还需要重写 onSaveInstanceState() 和 onRestoreInstanceState() 自己在两个实例状态之间进行转换(除了从每个方法链接到超类以继承默认行为)。Presumably, you have both the
Gallery
and theListView
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 overrideonSaveInstanceState()
andonRestoreInstanceState()
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).