我有一个由标签活动托管的活动。当我更改屏幕方向时,我的应用程序崩溃了。
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)
该应用程序在没有此自定义视图的情况下正常工作,但我需要使用它。
答案 0 :(得分:13)
不幸的是,我没有足够的声誉来发布图片。
XML文件不是图像,布局是XML文件。
我发现如果我从第一个标签删除listview或从第二个标签删除HorizontalListView,我可以毫无问题地改变方向
这加上你的症状,表明你将这两个小部件命名为android:id
值{{1}}。这是行不通的,因为他们保存的状态不一样。要么使它们成为同一个类,要么将它们命名为不同的类别。
答案 1 :(得分:0)
注意CommonsWare所说的,他是一个心灵读者:)
<小时/> 我只是留在这里存档。
顺便说一句:
android.view.AbsSavedState $ 1无法强制转换为android.widget.AbsListView $ SavedState