Android StackOverflow错误

时间:2011-04-20 02:00:08

标签: android stack-overflow

以下是我的堆栈跟踪。我仔细查看了它,但它只显示了一堆视图,坦率地说,我不太确定stackoverflow错误是什么。我读了一些其他问题,有些人通过迭代解决了他们的问题(再次,不知道那些是什么)。对于应用程序的基本布局,这是在崩溃时发生的:

TabView(5个标签)>第五个标签>按下按钮上的该选项卡中的webview。现在它确实崩溃,直到我点击后退按钮返回到第5个选项卡,并且它不会每次都这样做。

感谢您的帮助!

编辑:我在模拟器上停止测试,我还没有看到它在我的手机上崩溃。我会很感激并考虑任何进一步的帮助,但我认为这只是一个模拟器问题。

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

编辑:崩溃时发布代码。

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);

    }
}

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"
    />

3 个答案:

答案 0 :(得分:6)

您有太多嵌套的视图组(请参阅:java.lang.StackOverFlow error. Suspected too many views?以获取有关如何减少其中某些视图组的提示)

答案 1 :(得分:5)

通常会发生这种情况,因为在你的一个方法中,你一直在调用自己(我们称之为递归调用)。 检查你的方法以确保你调用super.whatever(),而不仅仅是()。此外,在这里发布您的代码会很棒,所以我们可以指出它到底发生了什么。

答案 2 :(得分:0)

有时StackOverflowErrro只能出现在特定设备上,因为它们具有不同的堆栈大小,您可以阅读article about StackoverflowError