Search code examples
javaandroidandroid-layoutstack-overflow

EditText causes StackOverflowError on older devices


I am using a third party tool to create a TableView similar to iPhone, you can see it here.

I have done a good bit of editing of this package, and have added the ability for a row to have an EditText. I tested it on different devices and it works great. Now the issue I am having is, if I have this UITableView inside a nested layout and give a row an edit text, when the user clicks the EditText on some older devices, it causes a stackoverflow.

This is within a fragment. The Structure looks like this

(1) (2) (3) (4) RelativeLayout -> RelativeLayout -> RelativeLayout -> ScrollLayout -> UITableView

There is bit of background behind this but long story short I need all these layouts, so removing one of them is not an option. This is frustrating as if I remove one of the RelativeLayouts, the app does not crash.

The android UITableView is also set up using several LinearLayouts. Ideally it would be great if I could set LinearLayout to be able to scroll, that way I could remove the ScrollLayout and the issue would be gone, but sadly I don't believe that is possible.

The error I am getting is

06-13 07:42:23.399: E/AndroidRuntime(1429): FATAL EXCEPTION: main
06-13 07:42:23.399: E/AndroidRuntime(1429): java.lang.StackOverflowError
06-13 07:42:23.399: E/AndroidRuntime(1429):     at android.view.ViewGroup.getChildVisibleRect(ViewGroup.java:2758)
06-13 07:42:23.399: E/AndroidRuntime(1429):     at android.view.ViewGroup.getChildVisibleRect(ViewGroup.java:2759)
06-13 07:42:23.399: E/AndroidRuntime(1429):     at android.view.ViewGroup.getChildVisibleRect(ViewGroup.java:2759)
06-13 07:42:23.399: E/AndroidRuntime(1429):     at android.view.ViewGroup.getChildVisibleRect(ViewGroup.java:2759)
06-13 07:42:23.399: E/AndroidRuntime(1429):     at android.view.ViewGroup.getChildVisibleRect(ViewGroup.java:2759)
06-13 07:42:23.399: E/AndroidRuntime(1429):     at android.view.ViewGroup.getChildVisibleRect(ViewGroup.java:2759)
06-13 07:42:23.399: E/AndroidRuntime(1429):     at android.view.ViewGroup.getChildVisibleRect(ViewGroup.java:2759)
06-13 07:42:23.399: E/AndroidRuntime(1429):     at android.view.ViewGroup.getChildVisibleRect(ViewGroup.java:2759)
06-13 07:42:23.399: E/AndroidRuntime(1429):     at android.view.ViewGroup.getChildVisibleRect(ViewGroup.java:2759)
06-13 07:42:23.399: E/AndroidRuntime(1429):     at android.view.ViewGroup.getChildVisibleRect(ViewGroup.java:2759)
06-13 07:42:23.399: E/AndroidRuntime(1429):     at android.view.ViewGroup.getChildVisibleRect(ViewGroup.java:2759)
06-13 07:42:23.399: E/AndroidRuntime(1429):     at android.view.ViewGroup.getChildVisibleRect(ViewGroup.java:2759)
06-13 07:42:23.399: E/AndroidRuntime(1429):     at android.view.ViewGroup.getChildVisibleRect(ViewGroup.java:2759)
06-13 07:42:23.399: E/AndroidRuntime(1429):     at android.view.ViewGroup.getChildVisibleRect(ViewGroup.java:2759)
06-13 07:42:23.399: E/AndroidRuntime(1429):     at android.view.ViewGroup.getChildVisibleRect(ViewGroup.java:2759)
06-13 07:42:23.399: E/AndroidRuntime(1429):     at android.view.ViewGroup.getChildVisibleRect(ViewGroup.java:2759)
06-13 07:42:23.399: E/AndroidRuntime(1429):     at android.view.ViewGroup.getChildVisibleRect(ViewGroup.java:2759)
06-13 07:42:23.399: E/AndroidRuntime(1429):     at android.view.ViewGroup.getChildVisibleRect(ViewGroup.java:2759)
06-13 07:42:23.399: E/AndroidRuntime(1429):     at android.widget.TextView$HandleView.isPositionVisible(TextView.java:8228)
06-13 07:42:23.399: E/AndroidRuntime(1429):     at android.widget.TextView$HandleView.moveTo(TextView.java:8245)
06-13 07:42:23.399: E/AndroidRuntime(1429):     at android.widget.TextView$HandleView.positionAtCursor(TextView.java:8340)
06-13 07:42:23.399: E/AndroidRuntime(1429):     at android.widget.TextView$InsertionPointCursorController.updatePosition(TextView.java:8401)
06-13 07:42:23.399: E/AndroidRuntime(1429):     at android.widget.TextView.updateCursorControllerPositions(TextView.java:4292)
06-13 07:42:23.399: E/AndroidRuntime(1429):     at android.widget.TextView.onDraw(TextView.java:4281)
06-13 07:42:23.399: E/AndroidRuntime(1429):     at android.view.View.draw(View.java:6986)
06-13 07:42:23.399: E/AndroidRuntime(1429):     at android.view.ViewGroup.drawChild(ViewGroup.java:1739)
06-13 07:42:23.399: E/AndroidRuntime(1429):     at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1466)
06-13 07:42:23.399: E/AndroidRuntime(1429):     at android.view.ViewGroup.drawChild(ViewGroup.java:1737)
06-13 07:42:23.399: E/AndroidRuntime(1429):     at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1466)
06-13 07:42:23.399: E/AndroidRuntime(1429):     at android.view.View.draw(View.java:6989)
06-13 07:42:23.399: E/AndroidRuntime(1429):     at android.view.ViewGroup.drawChild(ViewGroup.java:1739)
06-13 07:42:23.399: E/AndroidRuntime(1429):     at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1466)
06-13 07:42:23.399: E/AndroidRuntime(1429):     at android.view.View.draw(View.java:6989)
06-13 07:42:23.399: E/AndroidRuntime(1429):     at android.view.ViewGroup.drawChild(ViewGroup.java:1739)
06-13 07:42:23.399: E/AndroidRuntime(1429):     at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1466)
06-13 07:42:23.399: E/AndroidRuntime(1429):     at android.view.ViewGroup.drawChild(ViewGroup.java:1737)
06-13 07:42:23.399: E/AndroidRuntime(1429):     at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1466)
06-13 07:42:23.399: E/AndroidRuntime(1429):     at android.view.ViewGroup.drawChild(ViewGroup.java:1737)
06-13 07:42:23.399: E/AndroidRuntime(1429):     at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1466)
06-13 07:42:23.399: E/AndroidRuntime(1429):     at android.view.ViewGroup.drawChild(ViewGroup.java:1737)
06-13 07:42:23.399: E/AndroidRuntime(1429):     at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1466)
06-13 07:42:23.399: E/AndroidRuntime(1429):     at android.view.View.draw(View.java:7093)
06-13 07:42:23.399: E/AndroidRuntime(1429):     at android.widget.FrameLayout.draw(FrameLayout.java:361)
06-13 07:42:23.399: E/AndroidRuntime(1429):     at android.widget.ScrollView.draw(ScrollView.java:1421)
06-13 07:42:23.399: E/AndroidRuntime(1429):     at android.view.ViewGroup.drawChild(ViewGroup.java:1739)
06-13 07:42:23.399: E/AndroidRuntime(1429):     at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1466)
06-13 07:42:23.399: E/AndroidRuntime(1429):     at android.view.View.draw(View.java:6989)
06-13 07:42:23.399: E/AndroidRuntime(1429):     at android.view.ViewGroup.drawChild(ViewGroup.java:1739)
06-13 07:42:23.399: E/AndroidRuntime(1429):     at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1466)
06-13 07:42:23.399: E/AndroidRuntime(1429):     at android.view.ViewGroup.drawChild(ViewGroup.java:1737)
06-13 07:42:23.399: E/AndroidRuntime(1429):     at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1466)
06-13 07:42:23.399: E/AndroidRuntime(1429):     at android.view.ViewGroup.drawChild(ViewGroup.java:1737)
06-13 07:42:23.399: E/AndroidRuntime(1429):     at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1466)
06-13 07:42:23.399: E/AndroidRuntime(1429):     at android.view.ViewGroup.drawChild(ViewGroup.java:1737)
06-13 07:42:23.399: E/AndroidRuntime(1429):     at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1466)
06-13 07:42:23.399: E/AndroidRuntime(1429):     at android.view.ViewGroup.drawChild(ViewGroup.java:1737)
06-13 07:42:23.399: E/AndroidRuntime(1429):     at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1466)
06-13 07:42:23.399: E/AndroidRuntime(1429):     at android.view.View.draw(View.java:6989)
06-13 07:42:23.399: E/AndroidRuntime(1429):     at android.view.ViewGroup.drawChild(ViewGroup.java:1739)
06-13 07:42:23.399: E/AndroidRuntime(1429):     at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1466)
06-13 07:42:23.399: E/AndroidRuntime(1429):     at android.view.View.draw(View.java:6989)
06-13 07:42:23.399: E/AndroidRuntime(1429):     at android.widget.FrameLayout.draw(FrameLayout.java:361)
06-13 07:42:23.399: E/AndroidRuntime(1429):     at android.view.ViewGroup.drawChild(ViewGroup.java:1739)
06-13 07:42:23.399: E/AndroidRuntime(1429):     at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1466)
06-13 07:42:23.399: E/AndroidRuntime(1429):     at android.view.ViewGroup.drawChild(ViewGroup.java:1737)
06-13 07:42:23.399: E/AndroidRuntime(1429):     at android.view.Vi

I have tested this on many newer devices, Nexus, HTC etc and there is no issue. However when I tested this on an older device, the Sony Ericson Mini Pro 2 this error happens. I want to ensure this app does not crash on older devices, currently app supports 2.3.3+

Does anyone have any ideas as to what this recursive call is happening which is causing older devices to crash? And is there anyway to prevent this.

Any advice would be greatly appreciated.


Solution

  • The layout you have is too deep for some of the devices out there to handle. You have 4 layouts from what you posted(only from the fragment? if yes, then you also have layouts from the activity) + the UITableView. Now I don't know what changes did you made but from a quick look in the code for the UITableView is not very efficient. UITableView extends LinearLayout only to inflate another layout as its content which consists of a LinearLayout wrapping another Linearlayout. So the UITableView adds another three extra layouts not mentioning its content.

    Either drop the UITableView(are you sure you can't use a ListView(which would probably kill all performance problems/exceptions)), modify and improve it so it doesn't add so many levels in the layout or you keep it and modify the rest of the layout to be more efficient.