Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

class cast exception on orientation change (Android)

Tags:

android

I have an activity which is hosted by tab activity. When i change screen orientation my app crashes.

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

This line in manifest doesn't help:

android:configChanges="orientation|keyboardHidden"

And one thing else: in my activity i use custom view (horizontal ListView) from https://github.com/dinocore1/DevsmartLib-Android

The app is working fine without this custom view, but i need to use it.

like image 968
AndrOvip Avatar asked Feb 14 '13 17:02

AndrOvip


1 Answers

Unfortunately i don't have enough reputation to post images.

XML files are not images, and layouts are XML files.

I found that if i remove listview from first tab or HorizontalListView from the second, i can change orientation without any problem

That, plus your symptoms, suggests that you named those two widgets with the same android:id value. That will not work, as their saved states are not the same. Either make them be both the same class, or name them something different.

like image 135
CommonsWare Avatar answered Oct 17 '22 22:10

CommonsWare