How to debug (is it?) StackOverflowError with finite logarithm?

Sorry if this is widespread, inappropriate or deceiving, feel free to mark.

However, I couldn't find a solution. I get 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've spent hours right now trying to figure out what happened: I don't know about any recursive call in my code. I'm asking:

  • Do you have any idea what might be causing this problem?
  • Do you have any suggestions for a technical solution to these problems? Any way to get the "root" reason on the stack? There must be some kind of recursive movement, but it certainly has (a) a starting point and a challenge to that point; (b) the end when thrown StackOverflowError

    . We can see the end part, but not the beginning, because the logarithm stops.
+3


source to share


1 answer


I had this problem today while working with fragments. This code was enough for the error to occur:

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 a method inflater.inflate()

with two parameters, the inflator implicitly tries to attach the inflated view to the container. This causes the newly created view to already be anchored to the fragment, even if we haven't returned our view yet.

If we pass null as the second parameter, Android Studio reminds us that

When inflating a layout, avoid passing null as the parent view, as otherwise any layout parameters at the root of the layout will be ignored.



technically forcing us to fill in the second parameter.

The best way to manage it is to keep track of the container's parameters by passing it to a 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 latter false

says inflate

not to add the view to the container view we have provided.

So, to prevent this error in the future, how do you programmatically decide which method overload is being inflate

used?

  • Are you implementing a method that asks you to return a view and adding a view is not meant for you? (Snippets, ListAdapter ListView / Spinners ...)

    Use inflater.inflate(R.layout.something, container, false);

  • Are you building your interface from code and what you upload will be the container?

    Use inflater.inflate(R.layout.something, null);

  • Are you diluting something that you plan to manually add to another container?

    Use inflater.inflate(R.layout.something, container);

    and don't add the element to the container (it already does this).

+9


source







All Articles