Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android StackOverflowError in ViewGroup.resetResolvedTextDirection

I just went to android market to publish an update to my app and noticed there a few new errors reported from existing installs. While I can understand (and attempt to do something about) most of them, this one leaves me rather puzzled:

java.lang.StackOverflowError
at android.view.ViewGroup.resetResolvedTextDirection(ViewGroup.java:5131)
at android.view.ViewGroup.resetResolvedTextDirection(ViewGroup.java:5131)
at android.view.ViewGroup.resetResolvedTextDirection(ViewGroup.java:5131)
at android.view.ViewGroup.resetResolvedTextDirection(ViewGroup.java:5131)
at android.view.ViewGroup.resetResolvedTextDirection(ViewGroup.java:5131)
at android.view.ViewGroup.resetResolvedTextDirection(ViewGroup.java:5131)
... this line repeats about 200 times or so ...

This is all there is - no other information of any kind.

I'm totally stumped as to where to start investigating this. Any ideas are greatly appreciated.

like image 663
Aleks G Avatar asked Feb 07 '12 17:02

Aleks G


People also ask

What is android ViewGroup?

ViewGroup is a collection of Views(TextView, EditText, ListView, etc..), somewhat like a container. A View object is a component of the user interface (UI) like a button or a text box, and it's also called a widget.

What is child view in android?

In android (and most other technologies), views can have subviews, aka "children". Most views can have children and can be a child of a parent view. It's kind of like a "tree". The most obvious feature of being a child of some other view is that the child moves with the parent view.

What is view and view group?

Android ViewGroup The ViewGroup will provide an invisible containers to hold other Views or ViewGroups and to define the layout properties. For example, Linear Layout is the ViewGroup that contains a UI controls like button, textview, etc. and other layouts also.

Which of the following is a view group?

Android contains the following commonly used ViewGroup subclasses: LinearLayout. RelativeLayout. ListView.


3 Answers

That appears to be a method added in ICS, so it's 4.0 and over. Looking at the code it seems like you have some kind of view loop in your hierarchy since it's apparently the child.resetResolvedTextDirection(); line doing it. In other words, one of your ViewGroup classes in your layout has somehow gotten added as a child to itself somewhere down the line.

like image 190
Brian Dupuis Avatar answered Nov 08 '22 20:11

Brian Dupuis


I tracked down the problem. It seems to me like a bug in Android, which is exhibited when a View's visibility is explicitly set to VISIBLE but the view itself and the view's parent is not added to the main view.

I finally got around the problem by adding the ListView in question to XML instead of creating it in the code and moving the code setVisibility(View.VISIBLE) to after the entire view is added to the main view (i.e. parent hierarchy can be traced from each child all the way to the beginning).

At least I'm not getting this error any more.

like image 21
Aleks G Avatar answered Nov 08 '22 21:11

Aleks G


The issue is when you inflate the view such that inflater.inflate(R.layout.view_topic, this); and the parent of this view is still not visible / rendered on to the stage.

Make sure you render it after the parent is visible or call

View child = inflater.inflate(R.layout.view_topic, null); // null will give warning but it wont throw an exception
        this.addView(child);
like image 38
Archana Bajaj Avatar answered Nov 08 '22 21:11

Archana Bajaj