I'm sorry if this is broad, inappropriate or a dupe, feel free to flag.
However I couldn't find a solution. I'm getting StackOverflowError
, and Android Studio shows -
08-03 16:22:49.293 5163-5163/com.package E/AndroidRuntime﹕ FATAL EXCEPTION: main
java.lang.StackOverflowError
at android.view.ViewGroup.jumpDrawablesToCurrentState(ViewGroup.java:5384)
at android.view.ViewGroup.jumpDrawablesToCurrentState(ViewGroup.java:5388)
at android.view.ViewGroup.jumpDrawablesToCurrentState(ViewGroup.java:5388)
at android.view.ViewGroup.jumpDrawablesToCurrentState(ViewGroup.java:5388)
at android.view.ViewGroup.jumpDrawablesToCurrentState(ViewGroup.java:5388)
at android.view.ViewGroup.jumpDrawablesToCurrentState(ViewGroup.java:5388)
at android.view.ViewGroup.jumpDrawablesToCurrentState(ViewGroup.java:5388)
at android.view.ViewGroup.jumpDrawablesToCurrentState(ViewGroup.java:5388)
at android.view.ViewGroup.jumpDrawablesToCurrentState(ViewGroup.java:5388)
at android.view.ViewGroup.jumpDrawablesToCurrentState(ViewGroup.java:5388)
at android.view.ViewGroup.jumpDrawablesToCurrentState(ViewGroup.java:5388)
at android.view.ViewGroup.jumpDrawablesToCurrentState(ViewGroup.java:5388)
at android.view.ViewGroup.jumpDrawablesToCurrentState(ViewGroup.java:5388)
at android.view.ViewGroup.jumpDrawablesToCurrentState(ViewGroup.java:5388)
at android.view.ViewGroup.jumpDrawablesToCurrentState(ViewGroup.java:5388)
at android.view.ViewGroup.jumpDrawablesToCurrentState(ViewGroup.java:5388)
at android.view.ViewGroup.jumpDrawablesToCurrentState(ViewGroup.java:5388)
at android.view.ViewGroup.jumpDrawablesToCurrentState(ViewGroup.java:5388)
at android.view.ViewGroup.jumpDrawablesToCurrentState(ViewGroup.java:5388)
at android.view.ViewGroup.jumpDrawablesToCurrentState(ViewGroup.java:5388)
at android.view.ViewGroup.jumpDrawablesToCurrentState(ViewGroup.java:5388)
at android.view.ViewGroup.jumpDrawablesToCurrentState(ViewGroup.java:5388)
at android.view.ViewGroup.jumpDrawablesToCurrentState(ViewGroup.java:5388)
at android.view.ViewGroup.jumpDrawablesToCurrentState(ViewGroup.java:5388)
at android.view.ViewGroup.jumpDrawablesToCurrentState(ViewGroup.java:5388)
at android.view.ViewGroup.jumpDrawablesToCurrentState(ViewGroup.java:5388)
at android.view.ViewGroup.jumpDrawablesToCurrentState(ViewGroup.java:5388)
at android.view.ViewGroup.jumpDrawablesToCurrentState(ViewGroup.java:5388)
at android.view.ViewGroup.jumpDrawablesToCurrentState(ViewGroup.java:5388)
at android.view.ViewGroup.jumpDrawablesToCurrentState(ViewGroup.java:5388)
at android.view.ViewGroup.jumpDrawablesToCurrentState(ViewGroup.java:5388)
at android.view.ViewGroup.jumpDrawablesToCurrentState(ViewGroup.java:5388)
at android.view.ViewGroup.jumpDrawablesToCurrentState(ViewGroup.java:5388)
at android.view.ViewGroup.jumpDrawablesToCurrentState(ViewGroup.java:5388)
at android.view.ViewGroup.jumpDrawablesToCurrentState(ViewGroup.java:5388)
at android.view.ViewGroup.jumpDrawablesToCurrentState(ViewGroup.java:5388)
at android.view.ViewGroup.jumpDrawablesToCurrentState(ViewGroup.java:5388)
at android.view.ViewGroup.jumpDrawablesToCurrentState(ViewGroup.java:5388)
at android.view.ViewGroup.jumpDrawablesToCurrentState(ViewGroup.java:5388)
at android.view.ViewGroup.jumpDrawablesToCurrentState(ViewGroup.java:5388)
at android.view.ViewGroup.jumpDrawablesToCurrentState(ViewGroup.java:5388)
at android.view.ViewGroup.jumpDrawablesToCurrentState(ViewGroup.java:5388)
at android.view.ViewGroup.jumpDrawablesToCurrentState(ViewGroup.java:5388)
at android.view.ViewGroup.jumpDrawablesToCurrentState(ViewGroup.java:5388)
at android.view.ViewGroup.jumpDrawablesToCurrentState(ViewGroup.java:5388)
at android.view.ViewGroup.jumpDrawablesToCurrentState(ViewGroup.java:5388)
at android.view.ViewGroup.jumpDrawablesToCurrentState(ViewGroup.java:5388)
at android.view.ViewGroup.jumpDrawablesToCurrentState(ViewGroup.java:5388)
at android.view.ViewGroup.jumpDrawablesToCurrentState(ViewGroup.java:5388)
at android.view.ViewGroup.jumpDrawablesToCurrentState(ViewGroup.java:5388)
at android.view.ViewGroup.jumpDrawablesToCurrentState(ViewGroup.java:5388)
at android.view.ViewGroup.jumpDrawablesToCurrentState(ViewGroup.java:5388)
at android.view.ViewGroup.jumpDrawablesToCurrentState(V
I spent hours right now trying to understand what's wrong: I'm not aware of any recursive call in my code. I'm asking:
StackOverflowError
is thrown. We can see the end part, but not the start, because the logcat stops.The simplest solution is to carefully inspect the stack trace and detect the repeating pattern of line numbers. These line numbers indicate the code being recursively called. Once you detect these lines, you must carefully inspect your code and understand why the recursion never terminates.
Increase Thread Stack Size (-Xss) lang. StackOverflowError , the thread stack size can be increased to allow a larger number of invocations. Increasing the stack size can be useful, for example, when the program involves calling a large number of methods or using lots of local variables.
The error java. lang. StackOverflowError is thrown to indicate that the application's stack was exhausted, due to deep recursion i.e your program/script recurses too deeply.
StackOverflowError is an error which Java doesn't allow to catch, for instance, stack running out of space, as it's one of the most common runtime errors one can encounter.
I had this issue today working with fragments. This code was sufficient to cause the error:
public static class ProductionFragment extends Fragment {
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.something, container);
return view;
}
}
The solution was one of the following:
//The preferred way
View view = inflater.inflate(R.layout.something, container, false);
//Not optimal but still working way
View view = inflater.inflate(R.layout.something, null);
When I call inflater.inflate()
method with two params, the inflater implicitly tries to attach the inflated view to the container. This causes the newly created view to be already attached to the fragment even if we still didn't return our view.
If we pass a null as the second param, Android Studio reminds us that
When inflating a layout, avoid passing in null as the parent view, since otherwise any layout parameters on the root of the inflated layout will be ignored.
technically driving us to fill the second param.
The best way to manage it is to keep track of the container parameters by passing it to the function and NOT adding our view to the root. This is done by calling inflate
with three parameters:
inflater.inflate(R.layout.something, container, false);
where the last false
tells the inflate
method to not add the view to the container view we've supplied.
So, to prevent this mistake in the future, how to programmatically decide what overload of inflate
method use?
Are you implementing a method that asks you to return a view and the view appending is not not meant to be done by you? (Fragments, ListAdapter of ListView/Spinners...)
Use inflater.inflate(R.layout.something, container, false);
Are you building your interface from code and what you're loading is going to be the container?
Use inflater.inflate(R.layout.something, null);
Are you inflating something that you're planning to manually add to an another container?
Use inflater.inflate(R.layout.something, container);
and do not add the item to the container (it already does it).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With