10

我有一个由选项卡活动托管的活动。当我更改屏幕方向时,我的应用程序崩溃。

02-14 21:01:35.825: E/AndroidRuntime(9424): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.testapp/com.example.testapp.MainActivity}
java.lang.ClassCastException: android.view.AbsSavedState$1 cannot be cast to android.widget.AbsListView$SavedState
02-14 21:01:35.825: E/AndroidRuntime(9424):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2194)
02-14 21:01:35.825: E/AndroidRuntime(9424):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2229)
02-14 21:01:35.825: E/AndroidRuntime(9424):     at android.app.ActivityThread.handleRelaunchActivity(ActivityThread.java:3791)
02-14 21:01:35.825: E/AndroidRuntime(9424):     at android.app.ActivityThread.access$700(ActivityThread.java:139)
02-14 21:01:35.825: E/AndroidRuntime(9424):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1265)
02-14 21:01:35.825: E/AndroidRuntime(9424):     at android.os.Handler.dispatchMessage(Handler.java:99)
02-14 21:01:35.825: E/AndroidRuntime(9424):     at android.os.Looper.loop(Looper.java:154)
02-14 21:01:35.825: E/AndroidRuntime(9424):     at android.app.ActivityThread.main(ActivityThread.java:4945)
02-14 21:01:35.825: E/AndroidRuntime(9424):     at java.lang.reflect.Method.invokeNative(Native Method)
02-14 21:01:35.825: E/AndroidRuntime(9424):     at java.lang.reflect.Method.invoke(Method.java:511)
02-14 21:01:35.825: E/AndroidRuntime(9424):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
02-14 21:01:35.825: E/AndroidRuntime(9424):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
02-14 21:01:35.825: E/AndroidRuntime(9424):     at dalvik.system.NativeStart.main(Native Method)
02-14 21:01:35.825: E/AndroidRuntime(9424): Caused by: java.lang.ClassCastException: android.view.AbsSavedState$1 cannot be cast to android.widget.AbsListView$SavedState
02-14 21:01:35.825: E/AndroidRuntime(9424):     at android.widget.AbsListView.onRestoreInstanceState(AbsListView.java:1596)
02-14 21:01:35.825: E/AndroidRuntime(9424):     at android.view.View.dispatchRestoreInstanceState(View.java:9977)
02-14 21:01:35.825: E/AndroidRuntime(9424):     at android.view.ViewGroup.dispatchThawSelfOnly(ViewGroup.java:2346)
02-14 21:01:35.825: E/AndroidRuntime(9424):     at android.widget.AdapterView.dispatchRestoreInstanceState(AdapterView.java:778)
02-14 21:01:35.825: E/AndroidRuntime(9424):     at android.view.ViewGroup.dispatchRestoreInstanceState(ViewGroup.java:2332)
02-14 21:01:35.825: E/AndroidRuntime(9424):     at android.view.ViewGroup.dispatchRestoreInstanceState(ViewGroup.java:2332)
02-14 21:01:35.825: E/AndroidRuntime(9424):     at android.view.ViewGroup.dispatchRestoreInstanceState(ViewGroup.java:2332)
02-14 21:01:35.825: E/AndroidRuntime(9424):     at android.view.ViewGroup.dispatchRestoreInstanceState(ViewGroup.java:2332)
02-14 21:01:35.825: E/AndroidRuntime(9424):     at android.view.ViewGroup.dispatchRestoreInstanceState(ViewGroup.java:2332)
02-14 21:01:35.825: E/AndroidRuntime(9424):     at android.view.ViewGroup.dispatchRestoreInstanceState(ViewGroup.java:2332)
02-14 21:01:35.825: E/AndroidRuntime(9424):     at android.view.ViewGroup.dispatchRestoreInstanceState(ViewGroup.java:2332)
02-14 21:01:35.825: E/AndroidRuntime(9424):     at android.view.ViewGroup.dispatchRestoreInstanceState(ViewGroup.java:2332)
02-14 21:01:35.825: E/AndroidRuntime(9424):     at android.view.ViewGroup.dispatchRestoreInstanceState(ViewGroup.java:2332)
02-14 21:01:35.825: E/AndroidRuntime(9424):     at android.view.View.restoreHierarchyState(View.java:9955)
02-14 21:01:35.825: E/AndroidRuntime(9424):     at com.android.internal.policy.impl.PhoneWindow.restoreHierarchyState(PhoneWindow.java:1671)
02-14 21:01:35.825: E/AndroidRuntime(9424):     at android.app.Activity.onRestoreInstanceState(Activity.java:939)
02-14 21:01:35.825: E/AndroidRuntime(9424):     at android.app.TabActivity.onRestoreInstanceState(TabActivity.java:84)
02-14 21:01:35.825: E/AndroidRuntime(9424):     at android.app.Activity.performRestoreInstanceState(Activity.java:911)
02-14 21:01:35.825: E/AndroidRuntime(9424):     at android.app.Instrumentation.callActivityOnRestoreInstanceState(Instrumentation.java:1132)
   02-14 21:01:35.825: E/AndroidRuntime(9424):  at    android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2172)
  02-14 21:01:35.825: E/AndroidRuntime(9424):   ... 12 more

清单中的这一行没有帮助:

android:configChanges="orientation|keyboardHidden"

还有一件事:在我的活动中,我使用来自https://github.com/dinocore1/DevsmartLib-Android的自定义视图(水平 ListView)

没有此自定义视图,该应用程序运行良好,但我需要使用它。

4

2 回答 2

13

不幸的是,我没有足够的声誉来发布图片。

XML 文件不是图像,布局是 XML 文件。

我发现如果我从第一个选项卡中删除 listview 或从第二个选项卡中删除 Horizo​​ntalListView,我可以毫无问题地更改方向

加上您的症状,这表明您将这两个小部件命名为相同的android:id值。那是行不通的,因为他们保存的状态不一样。要么使它们成为同一类,要么将它们命名为不同的名称。

于 2013-02-15T12:37:54.723 回答
0

注意 CommonsWare 所说的话,他是个读心者 :)


我只是把这个留在这里存档。

照此办理:

android.view.AbsSavedState$1 不能转换为 android.widget.AbsListView$SavedState

  1. 检查您的导入以查看您是否使用了正确的类
  2. 在转换前做一个 instanceof 检查
  3. 粘贴java代码
于 2013-02-14T21:54:20.173 回答