11

I'm having a crash when refreshing a view inside a SlidingTray (custom SlidingDrawer coming from the top).

I'm not sure what causing it.. but my first guess is that it's due to the number of nested layouts...

What is the maximum number of nested layouts?

Is it device specific, how can I be sure if that's the cause?

If it's not, any of these things is causing it.. what is?

The stacktrace:

E/AndroidRuntime( 2199): FATAL EXCEPTION: main
E/AndroidRuntime( 2199): java.lang.StackOverflowError
E/AndroidRuntime( 2199): at android.graphics.Paint.measureText(Paint.java:1057)
E/AndroidRuntime( 2199): at android.text.Styled.drawDirectionalRun(Styled.java:267)
E/AndroidRuntime( 2199): at android.text.Styled.measureText(Styled.java:430)
E/AndroidRuntime( 2199): at android.text.Layout.measureText(Layout.java:1655)
E/AndroidRuntime( 2199): at android.text.Layout.getLineMax(Layout.java:689)
E/AndroidRuntime( 2199): at android.text.Layout.draw(Layout.java:340)
E/AndroidRuntime( 2199): at android.text.BoringLayout.draw(BoringLayout.java:365)
E/AndroidRuntime( 2199): at android.widget.TextView.onDraw(TextView.java:4168)
E/AndroidRuntime( 2199): at android.view.View.draw(View.java:6880)
E/AndroidRuntime( 2199): at android.view.ViewGroup.drawChild(ViewGroup.java:1646)
E/AndroidRuntime( 2199): at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1373)
E/AndroidRuntime( 2199): at android.view.ViewGroup.drawChild(ViewGroup.java:1644)
E/AndroidRuntime( 2199): at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1373)
E/AndroidRuntime( 2199): at android.view.ViewGroup.drawChild(ViewGroup.java:1644)
E/AndroidRuntime( 2199): at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1373)
E/AndroidRuntime( 2199): at android.view.View.draw(View.java:6883)
E/AndroidRuntime( 2199): at android.widget.FrameLayout.draw(FrameLayout.java:357)
E/AndroidRuntime( 2199): at android.widget.ScrollView.draw(ScrollView.java:1409)
E/AndroidRuntime( 2199): at android.view.ViewGroup.drawChild(ViewGroup.java:1646)
E/AndroidRuntime( 2199): at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1373)
E/AndroidRuntime( 2199): at android.view.ViewGroup.drawChild(ViewGroup.java:1644)
E/AndroidRuntime( 2199): at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1373)
E/AndroidRuntime( 2199): at android.view.View.draw(View.java:6883)
E/AndroidRuntime( 2199): at android.view.ViewGroup.drawChild(ViewGroup.java:1646)
E/AndroidRuntime( 2199): at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1373)
E/AndroidRuntime( 2199): at android.view.View.buildDrawingCache(View.java:6640)
E/AndroidRuntime( 2199): at android.view.View.getDrawingCache(View.java:6428)
E/AndroidRuntime( 2199): at android.view.ViewGroup.drawChild(ViewGroup.java:1571)
E/AndroidRuntime( 2199): at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1373)
E/AndroidRuntime( 2199): at android.view.ViewGroup.drawChild(ViewGroup.java:1644)
E/AndroidRuntime( 2199): at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1392)
E/AndroidRuntime( 2199): at android.view.ViewGroup.drawChild(ViewGroup.java:1644)
E/AndroidRuntime( 2199): at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1373)
E/AndroidRuntime( 2199): at android.view.ViewGroup.drawChild(ViewGroup.java:1644)
E/AndroidRuntime( 2199): at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1373)
E/AndroidRuntime( 2199): at android.view.ViewGroup.drawChild(ViewGroup.java:1644)
E/AndroidRuntime( 2199): at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1373)
E/AndroidRuntime( 2199): at android.view.View.draw(View.java:6883)
E/AndroidRuntime( 2199): at android.widget.FrameLayout.draw(FrameLayout.java:357)
E/AndroidRuntime( 2199): at android.widget.ScrollView.draw(ScrollView.java:1409)
E/AndroidRuntime( 2199): at android.view.ViewGroup.drawChild(ViewGroup.java:1646)
E/AndroidRuntime( 2199): at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1373)
E/AndroidRuntime( 2199): at android.view.ViewGroup.drawChild(ViewGroup.java:1644)
E/AndroidRuntime( 2199): at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1373)
E/AndroidRuntime( 2199): at android.view.ViewGroup.drawChild(ViewGroup.java:1644)
E/AndroidRuntime( 2199): at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1373)
E/AndroidRuntime( 2199): at android.view.View.draw(View.java:6986)
E/AndroidRuntime( 2199): at android.widget.FrameLayout.draw(FrameLayout.java:357)
E/AndroidRuntime( 2199): at android.widget.HorizontalScrollView.draw(HorizontalScrollView.java:1409)
E/AndroidRuntime( 2199): at android.view.ViewGroup.drawChild(ViewGroup.java:1646)
E/AndroidRuntime( 2199): at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1373)
E/AndroidRuntime( 2199): at android.view.View.draw(View.java:6883)
E/AndroidRuntime( 2199): at android.view.ViewGroup.drawChild(ViewGroup.java:1646)
E/AndroidRuntime( 2199): at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1373)
E/AndroidRuntime( 2199): at android.view.View.draw(View.java:6883)
E/AndroidRuntime( 2199): at android.view.ViewGroup.drawChild(ViewGroup.java:1646)
E/AndroidRuntime( 2199): at com.vodafone.onm.components.SlidingTray.dispatchDraw(SlidingTray.java:426)
E/AndroidRuntime( 2199): at android.view.ViewGroup.drawChild(ViewGroup.java:1644)
E/AndroidRuntime( 2199): at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1373)
E/AndroidRuntime( 2199): at android.view.ViewGroup.drawChild(ViewGroup.java:1644)
E/AndroidRuntime( 2199): at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1373)
E/AndroidRuntime( 2199): at android.view.ViewGroup.drawChild(ViewGroup.java:1644)
E/AndroidRuntime( 2199): at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1373)
E/AndroidRuntime( 2199): at android.view.View.draw(View.java:6883)
E/AndroidRuntime( 2199): at android.widget.FrameLayout.draw(FrameLayout.java:357)
E/AndroidRuntime( 2199): at android.view.ViewGroup.drawChild(ViewGroup.java:1646)
E/AndroidRuntime( 2199): at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1373)
E/AndroidRuntime( 2199): at android.view.View.draw(View.java:6883)
E/AndroidRuntime( 2199): at android.widget.FrameLayout.draw(FrameLayout.java:357)
E/AndroidRuntime( 2199): at com.android.internal.policy.impl.PhoneWindow$DecorView.draw(PhoneWindow.java)

UPDATE: Hierarchy Viewer Snapshot

.

Some thinks I think are related: http://www.mail-archive.com/android-developers@googlegroups.com/msg48036.html

neteinstein
  • 17,529
  • 11
  • 93
  • 123
  • Please post some code for the createView or whatever you are doing – jsimpson Mar 30 '12 at 15:53
  • 1
    It's too much code :-S , but how about a hierarchy viewer snapshot of it? – neteinstein Mar 30 '12 at 15:58
  • 1
    Just make sure you are not somehow causing recursive calls while recycing/drawing. If you aren't then too many nested views could be the problem. As for the limit, it would depend on the stack size, and i think this is firmware-dependent. – jsimpson Mar 30 '12 at 16:01
  • Posting your desired layout as well as your view heirarchy would help. A better way to look at it would likely be "what is the fewest nested views I can use to achieve this" – jqpubliq Mar 30 '12 at 16:03
  • I agree with jqpubliq - Your view hierarchy is way too deep. Android has a lot of flexibility in its layout tools, which makes it way easier to write a shallow hierarchy than you could with HTML – JRaymond Mar 30 '12 at 16:25
  • 1
    The problem is that I have a SlidingDrawer/Tray with pull to refresh, horizontal scroll with several pages which each have vertical scroll views, with 4 big buttons which each have it's own scroll view... with data inside them... – neteinstein Mar 30 '12 at 16:28
  • 1
    Holy smokes. So (to get a bit technical), this looks a little cray-cray. There are a couple pretty solid runs of views with only one child which should be collapsible through or something. Also some of the stuff you are doing sounds scary, you should look into ViewPager or something and rethink your layout – jqpubliq Mar 30 '12 at 16:36

1 Answers1

22

What is the maximum number of nested layouts?

There is no specific value. You run out of stack space when you run out of stack space, and that will be contingent upon what you are doing. The main application thread has an 8KB stack, last I heard.

That being said, if Hierarchy View is showing a depth of 10 or more (root to deepest leaf), I start to get nervous, and by 15 you are likely to start running into exceptions. Your image, which is nearly illegible, appears to have a depth substantially higher than that.

You seem to have a number of wasted layers. If you have a layer in Hierarchy View, on the critical path, that has one parent and one child, that is a prime candidate to be removed, as it may not be adding any value. You have at least 5 of these candidates. Even cleaning all of that up may not be sufficient, but it is a starting point.

CommonsWare
  • 986,068
  • 189
  • 2,389
  • 2,491
  • Thanks, i'm trying to reduce to 15 (removing some features). I'll get back when i have done it and test it. – neteinstein Mar 31 '12 at 19:16
  • It worked. With 17 layers of depth it works without crashes.. but i'm also wondering if one of the things i removed also helped in solving the crasha. I used view.layout(...) to move a view to simulate a ScrollView (to create a Pull to Refresh that with a scroll view would be very complicated). Do you have any clues if this together with the refresh of the moving screen can also cause a crash like that? – neteinstein Apr 01 '12 at 21:25
  • @NeTeInStEiN: I have no clue, sorry. – CommonsWare Apr 01 '12 at 21:32
  • @CommonsWare I have the similar issues i am getting stackoverflow error As you said **If you have a layer in Hierarchy View, on the critical path, that has one parent and one child, that is a prime candidate to be removed, as it may not be adding any value.** Can you explain it a bit more. I think my issue is because of this. I am including one layout which is `TableLayout` and it has only one `TableRow` with six images. Can you please elaborate this. – BBdev Apr 08 '13 at 07:27
  • @BBdev: " I am including one layout which is TableLayout and it has only one TableRow with six images. Can you please elaborate this." -- replace this with a horizontal `LinearLayout`. You are gaining no value from having a single-row `TableLayout`. – CommonsWare Apr 08 '13 at 12:01
  • @CommonsWare I had tried the same previously as you told but my application got crashed with stackoverflow error. Its always happens when i switch the activity more than four times my view is shown and within a second the application got crashed. – BBdev Apr 09 '13 at 03:53
  • The sweet spot for Android 2.x seems to be max depth of 17 layers. Above this and it goes boom. This is what I found on a 2.3.5 device and a 2.3.7 emulator at least. – Espen Riskedal Mar 24 '14 at 21:03