gpt4 book ai didi

android - AbsSpinner$SavedState 无法转换为 AbsListView$SavedState

转载 作者:太空狗 更新时间:2023-10-29 12:55:58 26 4
gpt4 key购买 nike

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

库在恢复时可以很好地读取列表的信息。它是无法读取图库保存状态的列表。我附上了下面的堆栈跟踪,尽管它告诉我的很少。您可以发出的任何光线都会有所帮助!顺便说一句,目标 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

最佳答案

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

关于android - AbsSpinner$SavedState 无法转换为 AbsListView$SavedState,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6796161/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com