tags:

views:

494

answers:

2

Hi,

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

A: 

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)
CommonsWare
Actually, yes... I do have activities as contents for the tab...eg.intent = new Intent().setClass(this, CategoryView.class); spec = tabHost.newTabSpec("Topics").setIndicator("Topics", res.getDrawable(R.drawable.ic_tab_artists)).setContent(intent); tabHost.addTab(spec);where the CategoryView extends Activity.So can you tell me what I would need to have as contents for the tabs ????
I had used an example from http://www.androidsnippets.info/snippets/68/Can you tell me why we should not use activities???
Well, others like putting activities as the contents of tabs, but all I can see is that they take up more memory, more CPU time, and more stack space, making applications work worse. You can set up your tabs to have simple `Views` as their contents, such as this project: http://github.com/commonsguy/cw-android/tree/master/Fancy/Tab/ Even if you leave your activities alone, you need to change the layouts those activities use so that all of their widgets' `android:id` values are unique.
CommonsWare
Unfortunately I cannot change the contents of the tab without making major modifications to the app. So I think I'll stick with this implementation. I also checked the android ids and they are unique across all the activities. Now, I'm very very confused again. One thing I realised is that this happens on the activity's onRestoreInstanceState method. I'm not overriding this method so am thinking that the default method which is there might be throwing the classcastexception. Can you tell me if you know anything about this?
Android has default implementations of `onSaveInstanceState()` and `onRestoreInstanceState()` that handle known user-mutable widgets. For example, if you have an `EditText` widget in your activity, the default `onSaveInstanceState()` will persist its value in the `Bundle` and the default `onRestoreInstanceState()` will restore its value from the `Bundle`.
CommonsWare
So, what my theory is that, probably when the users are multitasking then possibility is that the history might be cleared by the OS and possibly the data held by the app could have been cleared as well. So when the user is returning to the app and when onRestoreInstance is called the ClassCastException is thrown because of this. Could this be possible ?? I'm asking this because of the lineat android.app.Activity.onRestoreInstanceState(Activity.java:835)
Also because I tried doing one test. I had a lot of apps running and I hit home, went to settings and cleared the cache. When I came back to the app it crashed with a nullpointerexception.
A: 

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???