Android StackOverflow Error

浪子不回头ぞ 提交于 2019-11-28 09:56:03

问题


The following is my stacktrace. I looked through it but it just shows a bunch of views and frankly I'm not too sure what a stackoverflow error is exactly. I read on some of the other questions that some solved theirs through iterations (again, no idea what those are). For the basic layout of the app this is coming from when this crashes is:

TabView (5 tabs) > 5th tab > webview in that tab on button press. Now it does actually crash until i hit the back button to go back to the 5th tab and it doesn't do it every time.

Thanks for the help!

Edit: I stopped testing on the emulator and I have yet to see it crash on my phone. I will appreciate and look into any further help given but I think it was just an emulator issue.

04-20 01:52:26.510: ERROR/AndroidRuntime(23240): FATAL EXCEPTION: main
04-20 01:52:26.510: ERROR/AndroidRuntime(23240): java.lang.StackOverflowError
04-20 01:52:26.510: ERROR/AndroidRuntime(23240):     at android.view.ViewRoot.checkThread(ViewRoot.java:2801)
04-20 01:52:26.510: ERROR/AndroidRuntime(23240):     at android.view.ViewRoot.requestChildFocus(ViewRoot.java:1567)
04-20 01:52:26.510: ERROR/AndroidRuntime(23240):     at android.view.ViewGroup.requestChildFocus(ViewGroup.java:431)
04-20 01:52:26.510: ERROR/AndroidRuntime(23240):     at android.view.ViewGroup.requestChildFocus(ViewGroup.java:431)
04-20 01:52:26.510: ERROR/AndroidRuntime(23240):     at android.view.ViewGroup.requestChildFocus(ViewGroup.java:431)
04-20 01:52:26.510: ERROR/AndroidRuntime(23240):     at android.view.ViewGroup.requestChildFocus(ViewGroup.java:431)
04-20 01:52:26.510: ERROR/AndroidRuntime(23240):     at android.view.ViewGroup.requestChildFocus(ViewGroup.java:431)
04-20 01:52:26.510: ERROR/AndroidRuntime(23240):     at android.view.ViewGroup.requestChildFocus(ViewGroup.java:431)
04-20 01:52:26.510: ERROR/AndroidRuntime(23240):     at android.view.View.handleFocusGainInternal(View.java:2486)
04-20 01:52:26.510: ERROR/AndroidRuntime(23240):     at android.view.View.requestFocus(View.java:3605)
04-20 01:52:26.510: ERROR/AndroidRuntime(23240):     at android.view.View.requestFocus(View.java:3556)
04-20 01:52:26.510: ERROR/AndroidRuntime(23240):     at android.view.View.requestFocus(View.java:3534)
04-20 01:52:26.510: ERROR/AndroidRuntime(23240):     at android.widget.TabWidget.onFocusChange(TabWidget.java:425)
04-20 01:52:26.510: ERROR/AndroidRuntime(23240):     at android.view.View.onFocusChanged(View.java:2666)
04-20 01:52:26.510: ERROR/AndroidRuntime(23240):     at android.view.View.handleFocusGainInternal(View.java:2489)
04-20 01:52:26.510: ERROR/AndroidRuntime(23240):     at android.view.ViewGroup.handleFocusGainInternal(ViewGroup.java:405)
04-20 01:52:26.510: ERROR/AndroidRuntime(23240):     at android.view.View.requestFocus(View.java:3605)
04-20 01:52:26.510: ERROR/AndroidRuntime(23240):     at android.view.ViewGroup.requestFocus(ViewGroup.java:1028)
04-20 01:52:26.510: ERROR/AndroidRuntime(23240):     at android.view.ViewGroup.onRequestFocusInDescendants(ViewGroup.java:1073)
04-20 01:52:26.510: ERROR/AndroidRuntime(23240):     at android.view.ViewGroup.requestFocus(ViewGroup.java:1029)
04-20 01:52:26.510: ERROR/AndroidRuntime(23240):     at android.view.View.requestFocus(View.java:3556)
04-20 01:52:26.510: ERROR/AndroidRuntime(23240):     at android.widget.TabHost$1.onKey(TabHost.java:121)
04-20 01:52:26.510: ERROR/AndroidRuntime(23240):     at android.view.View.dispatchKeyEvent(View.java:3735)
04-20 01:52:26.510: ERROR/AndroidRuntime(23240):     at android.view.ViewGroup.dispatchKeyEvent(ViewGroup.java:788)
04-20 01:52:26.510: ERROR/AndroidRuntime(23240):     at android.view.ViewGroup.dispatchKeyEvent(ViewGroup.java:788)
04-20 01:52:26.510: ERROR/AndroidRuntime(23240):     at android.widget.TabHost$1.onKey(TabHost.java:122)
04-20 01:52:26.510: ERROR/AndroidRuntime(23240):     at android.view.View.dispatchKeyEvent(View.java:3735)
04-20 01:52:26.510: ERROR/AndroidRuntime(23240):     at android.view.ViewGroup.dispatchKeyEvent(ViewGroup.java:788)
04-20 01:52:26.510: ERROR/AndroidRuntime(23240):     at android.view.ViewGroup.dispatchKeyEvent(ViewGroup.java:788)
04-20 01:52:26.510: ERROR/AndroidRuntime(23240):     at android.widget.TabHost$1.onKey(TabHost.java:122)
04-20 01:52:26.510: ERROR/AndroidRuntime(23240):     at android.view.View.dispatchKeyEvent(View.java:3735)
04-20 01:52:26.510: ERROR/AndroidRuntime(23240):     at android.view.ViewGroup.dispatchKeyEvent(ViewGroup.java:788)
04-20 01:52:26.510: ERROR/AndroidRuntime(23240):     at android.view.ViewGroup.dispatchKeyEvent(ViewGroup.java:788)
04-20 01:52:26.510: ERROR/AndroidRuntime(23240):     at android.widget.TabHost$1.onKey(TabHost.java:122)
04-20 01:52:26.510: ERROR/AndroidRuntime(23240):     at android.view.View.dispatchKeyEvent(View.java:3735)
04-20 01:52:26.510: ERROR/AndroidRuntime(23240):     at android.view.ViewGroup.dispatchKeyEvent(ViewGroup.java:788)
04-20 01:52:26.510: ERROR/AndroidRuntime(23240):     at android.view.ViewGroup.dispatchKeyEvent(ViewGroup.java:788)
04-20 01:52:26.510: ERROR/AndroidRuntime(23240):     at android.widget.TabHost$1.onKey(TabHost.java:122)
04-20 01:52:26.510: ERROR/AndroidRuntime(23240):     at android.view.View.dispatchKeyEvent(View.java:3735)
04-20 01:52:26.510: ERROR/AndroidRuntime(23240):     at android.view.ViewGroup.dispatchKeyEvent(ViewGroup.java:788)
04-20 01:52:26.510: ERROR/AndroidRuntime(23240):     at android.view.ViewGroup.dispatchKeyEvent(ViewGroup.java:788)
04-20 01:52:26.510: ERROR/AndroidRuntime(23240):     at android.widget.TabHost$1.onKey(TabHost.java:122)
04-20 01:52:26.510: ERROR/AndroidRuntime(23240):     at android.view.View.dispatchKeyEvent(View.java:3735)
04-20 01:52:26.510: ERROR/AndroidRuntime(23240):     at android.view.ViewGroup.dispatchKeyEvent(ViewGroup.java:788)
04-20 01:52:26.510: ERROR/AndroidRuntime(23240):     at android.view.ViewGroup.dispatchKeyEvent(ViewGroup.java:788)
04-20 01:52:26.510: ERROR/AndroidRuntime(23240):     at android.widget.TabHost$1.onKey(TabHost.java:122)
04-20 01:52:26.510: ERROR/AndroidRuntime(23240):     at android.view.View.dispatchKeyEvent(View.java:3735)
04-20 01:52:26.510: ERROR/AndroidRuntime(23240):     at android.view.ViewGroup.dispatchKeyEvent(ViewGroup.java:788)
04-20 01:52:26.510: ERROR/AndroidRuntime(23240):     at android.view.ViewGroup.dispatchKeyEvent(ViewGroup.java:788)
04-20 01:52:26.510: ERROR/AndroidRuntime(23240):     at android.widget.TabHost$1.onKey(TabHost.java:122)
04-20 01:52:26.510: ERROR/AndroidRuntime(23240):     at android.view.View.dispatchKeyEvent(View.java:3735)
04-20 01:52:26.510: ERROR/AndroidRuntime(23240):     at android.view.ViewGroup.dispatchKeyEvent(ViewGroup.java:788)
04-20 01:52:26.510: ERROR/AndroidRuntime(23240):     at android.view.ViewGroup.dispatchKeyEvent(ViewGroup.java:788)
04-20 01:52:26.510: ERROR/AndroidRuntime(23240):     at android.widget.TabHost$1.onKey(TabHost.java:122)
04-20 01:52:26.510: ERROR/AndroidRuntime(23240):     at android.view.View.dispatchKeyEvent(View.java:3735)
04-20 01:52:26.510: ERROR/AndroidRuntime(23240):     at android.view.ViewGroup.dispatchKeyEvent(ViewGroup.java:788)
04-20 01:52:26.510: ERROR/AndroidRuntime(23240):     at android.view.ViewGroup.dispatchKeyEvent(ViewGroup.java:788)
04-20 01:52:26.510: ERROR/AndroidRuntime(23240):     at android.widget.TabHost$1.onKey(TabHost.java:122)
04-20 01:52:26.510: ERROR/AndroidRuntime(23240):     at android.view.View.dispatchKeyEvent(View.java:3735)
04-20 01:52:26.510: ERROR/AndroidRuntime(23240):     at android.view.ViewGroup.dispatchKeyEvent(ViewGroup.java:788)
04-20 01:52:26.510: ERROR/AndroidRuntime(23240):     at android.view.ViewGroup.dispatchKeyEvent(ViewGroup.java:788)
04-20 01:52:26.510: ERROR/AndroidRuntime(23240):     at android.widget.TabHost$1.onKey(TabHost.java:122)
04-20 01:52:26.510: ERROR/AndroidRuntime(23240):     at android.view.View.dispatchKeyEvent(View.java:3735)
04-20 01:52:26.510: ERROR/AndroidRuntime(23240):     at android.view.ViewGroup.dispatchKeyEvent(ViewGroup.java:788)
04-20 01:52:26.510: ERROR/AndroidRuntime(23240):     at android.view.ViewGroup.dispatchKeyEvent(ViewGroup.java:788)
04-20 01:52:26.510: ERROR/AndroidRuntime(23240):     at android.widget.TabHost$1.onKey(TabHost.java:122)
04-20 01:52:26.510: ERROR/AndroidRuntime(23240):     at android.view.View.dispatchKeyEvent(View.java:3735)
04-20 01:52:26.510: ERROR/AndroidRuntime(23240):     at android.view.ViewGroup.d

Edit: Posting code on crash.

public class TwitterAuthUrl extends Activity {

    final static String TAG = "TwitterAuthUrl";
    WebView mWebView;

    public void onCreate(Bundle savedInstanceState){
        super.onCreate(savedInstanceState);
        setContentView(R.layout.twitterauthurl);
        Bundle extras = getIntent().getExtras();

        OAuthConsumer consumer = new DefaultOAuthConsumer("xxxxxxxxxxxxxxxxxxxxx",
        "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx");

        OAuthProvider provider = new DefaultOAuthProvider(
        "http://twitter.com/oauth/request_token",
        "http://twitter.com/oauth/access_token",
        "http://twitter.com/oauth/authorize");


        String authUrl = null;
        try {
            authUrl = provider.retrieveRequestToken(consumer, OAuth.OUT_OF_BAND);
            Log.d(TAG, "Success authUrl " + authUrl);
        } catch (OAuthMessageSignerException e) {
            e.printStackTrace();
        } catch (OAuthNotAuthorizedException e) {
            e.printStackTrace();
        } catch (OAuthExpectationFailedException e) {
            e.printStackTrace();
        } catch (OAuthCommunicationException e) {
            e.printStackTrace();
        }

        mWebView = (WebView) findViewById(R.id.webview);
        mWebView.getSettings().setJavaScriptEnabled(true);
        mWebView.loadUrl(authUrl);
        Log.d(TAG, "authUrl = " + authUrl);

    }
}

The XML:

<?xml version="1.0" encoding="utf-8"?>
    <WebView  xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@+id/webview"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
    />

回答1:


You have too many nested viewgroups (see: java.lang.StackOverFlow error. Suspected too many views? for tips on how to reduce some of them)




回答2:


Usually this happens because in one of your methods, you keep calling yourself (we call it recursive call). Check your method to make sure you call super.whatever(), and not just whatever(). Also, it'd be great to post your code here so we can point to where exactly it happens.




回答3:


Sometimes StackOverflowErrro can appear on only particular devices because they have different stack size you can read article about StackoverflowError.



来源:https://stackoverflow.com/questions/5724758/android-stackoverflow-error

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!