Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Classcastexception occurs randomly

Tags:

android

I've an application in the market and many users have reported that the app is crashing a lot randomly. I'm trying to fix this but cannot fully understand the logs. Here's a extract from the log,

04-16 13:16:32.407 E/AndroidRuntime( 9237): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.maya.mobile.chiki/com.maya.mobile.chiki.tabview.Tabs3}: java.lang.RuntimeException: Unable to start activity ComponentInfo{com.maya.mobile.chiki/com.maya.mobile.chiki.featured.FeaturedView}: java.lang.ClassCastException: android.view.AbsSavedState$1
04-16 13:16:32.407 E/AndroidRuntime( 9237): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2496)
04-16 13:16:32.407 E/AndroidRuntime( 9237): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2512)
04-16 13:16:32.407 E/AndroidRuntime( 9237): at android.app.ActivityThread.access$2200(ActivityThread.java:119)
04-16 13:16:32.407 E/AndroidRuntime( 9237): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1863)
04-16 13:16:32.407 E/AndroidRuntime( 9237): at android.os.Handler.dispatchMessage(Handler.java:99)
04-16 13:16:32.407 E/AndroidRuntime( 9237): at android.os.Looper.loop(Looper.java:123)
04-16 13:16:32.407 E/AndroidRuntime( 9237): at android.app.ActivityThread.main(ActivityThread.java:4363)
04-16 13:16:32.407 E/AndroidRuntime( 9237): at java.lang.reflect.Method.invokeNative(Native Method)
04-16 13:16:32.407 E/AndroidRuntime( 9237): at java.lang.reflect.Method.invoke(Method.java:521)
04-16 13:16:32.407 E/AndroidRuntime( 9237): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:860)
04-16 13:16:32.407 E/AndroidRuntime( 9237): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618)
04-16 13:16:32.407 E/AndroidRuntime( 9237): at dalvik.system.NativeStart.main(Native Method)
04-16 13:16:32.407 E/AndroidRuntime( 9237): Caused by: java.lang.RuntimeException: Unable to start activity ComponentInfo{com.maya.mobile.chiki/com.maya.mobile.chiki.featured.FeaturedView}: java.lang.ClassCastException: android.view.AbsSavedState$1
04-16 13:16:32.407 E/AndroidRuntime( 9237): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2496)
04-16 13:16:32.407 E/AndroidRuntime( 9237): at android.app.ActivityThread.startActivityNow(ActivityThread.java:2335)
04-16 13:16:32.407 E/AndroidRuntime( 9237): at android.app.LocalActivityManager.moveToState(LocalActivityManager.java:127)
04-16 13:16:32.407 E/AndroidRuntime( 9237): at android.app.LocalActivityManager.startActivity(LocalActivityManager.java:339)
04-16 13:16:32.407 E/AndroidRuntime( 9237): at android.widget.TabHost$IntentContentStrategy.getContentView(TabHost.java:648)
04-16 13:16:32.407 E/AndroidRuntime( 9237): at android.widget.TabHost.setCurrentTab(TabHost.java:320)
04-16 13:16:32.407 E/AndroidRuntime( 9237): at com.maya.mobile.chiki.tabview.CustomTabHost.setCurrentTab(CustomTabHost.java:43)
04-16 13:16:32.407 E/AndroidRuntime( 9237): at android.widget.TabHost.addTab(TabHost.java:213)
04-16 13:16:32.407 E/AndroidRuntime( 9237): at com.maya.mobile.chiki.tabview.Tabs3.doCreateTabs(Tabs3.java:180)
04-16 13:16:32.407 E/AndroidRuntime( 9237): at com.maya.mobile.chiki.tabview.Tabs3.onCreate(Tabs3.java:149)
04-16 13:16:32.407 E/AndroidRuntime( 9237): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
04-16 13:16:32.407 E/AndroidRuntime( 9237): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2459)
04-16 13:16:32.407 E/AndroidRuntime( 9237): ... 11 more
04-16 13:16:32.407 E/AndroidRuntime( 9237): Caused by: java.lang.ClassCastException: android.view.AbsSavedState$1
04-16 13:16:32.407 E/AndroidRuntime( 9237): at android.widget.AbsSpinner.onRestoreInstanceState(AbsSpinner.java:440)
04-16 13:16:32.407 E/AndroidRuntime( 9237): at android.view.View.dispatchRestoreInstanceState(View.java:5940)
04-16 13:16:32.407 E/AndroidRuntime( 9237): at android.view.ViewGroup.dispatchThawSelfOnly(ViewGroup.java:1140)
04-16 13:16:32.407 E/AndroidRuntime( 9237): at android.widget.AdapterView.dispatchRestoreInstanceState(AdapterView.java:767)
04-16 13:16:32.407 E/AndroidRuntime( 9237): at android.view.ViewGroup.dispatchRestoreInstanceState(ViewGroup.java:1127)
04-16 13:16:32.407 E/AndroidRuntime( 9237): at android.view.ViewGroup.dispatchRestoreInstanceState(ViewGroup.java:1127)
04-16 13:16:32.407 E/AndroidRuntime( 9237): at android.view.ViewGroup.dispatchRestoreInstanceState(ViewGroup.java:1127)
04-16 13:16:32.407 E/AndroidRuntime( 9237): at android.view.ViewGroup.dispatchRestoreInstanceState(ViewGroup.java:1127)
04-16 13:16:32.407 E/AndroidRuntime( 9237): at android.view.View.restoreHierarchyState(View.java:5919)
04-16 13:16:32.407 E/AndroidRuntime( 9237): at com.android.internal.policy.impl.PhoneWindow.restoreHierarchyState(PhoneWindow.java:1454)
04-16 13:16:32.407 E/AndroidRuntime( 9237): at android.app.Activity.onRestoreInstanceState(Activity.java:835)
04-16 13:16:32.407 E/AndroidRuntime( 9237): at android.app.Activity.performRestoreInstanceState(Activity.java:807)
04-16 13:16:32.407 E/AndroidRuntime( 9237): at android.app.Instrumentation.callActivityOnRestoreInstanceState(Instrumentation.java:1096)
04-16 13:16:32.407 E/AndroidRuntime( 9237): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2473)
04-16 13:16:32.407 E/AndroidRuntime( 9237): ... 22 more

I got this log from one of my users.

Any help on this would be very very helpful.

Regards, Hari


I was finally able to replicate this issue through an emulator set up with 50MB memory and running on GSM network speed. The issue seems to be because of history being cleared and so the data being lost which the app was already having. Not sure how I can handle this though.. any help???

like image 879
HariKJ Avatar asked Apr 19 '10 11:04

HariKJ


People also ask

Why do we get ClassCastException?

Introduction. ClassCastException is a runtime exception raised in Java when we try to improperly cast a class from one type to another. It's thrown to indicate that the code has attempted to cast an object to a related class, but of which it is not an instance.

What code will cause a ClassCastException to be thrown?

Class ClassCastException Thrown to indicate that the code has attempted to cast an object to a subclass of which it is not an instance. For example, the following code generates a ClassCastException : Object x = new Integer(0); System.

How do you avoid ClassCastException?

To prevent the ClassCastException exception, one should be careful when casting objects to a specific class or interface and ensure that the target type is a child of the source type, and that the actual object is an instance of that type.

Which method throws ClassCastException?

ClassCast Exception is thrown when we try to cast an object of the parent class to the child class object. However, it can also be thrown when we try to convert the objects of two individual classes that don't have any relationship between them.


1 Answers

My guess is that:

  • You have an activity containing a TabHost (fine)
  • The contents of those tabs are activities (bad)
  • You are duplicating android:id values among some of the widgets in those activities (fatal)
like image 152
CommonsWare Avatar answered Oct 20 '22 09:10

CommonsWare