3

我知道这种类型的错误存在一些问题,但我的只是随机发生,我还没有找到导致它的原因。这是错误日志:

11-02 16:41:58.448: E/AndroidRuntime(13702): FATAL EXCEPTION: main
11-02 16:41:58.448: E/AndroidRuntime(13702): java.lang.StackOverflowError
11-02 16:41:58.448: E/AndroidRuntime(13702):    at android.text.SpannableString.getSpans(SpannableString.java:25)
11-02 16:41:58.448: E/AndroidRuntime(13702):    at android.text.TextUtils.writeToParcel(TextUtils.java:615)
11-02 16:41:58.448: E/AndroidRuntime(13702):    at android.widget.TextView$SavedState.writeToParcel(TextView.java:8781)
11-02 16:41:58.448: E/AndroidRuntime(13702):    at android.os.Parcel.writeParcelable(Parcel.java:1254)
11-02 16:41:58.448: E/AndroidRuntime(13702):    at android.os.Parcel.writeValue(Parcel.java:1173)
11-02 16:41:58.448: E/AndroidRuntime(13702):    at android.os.Parcel.writeSparseArray(Parcel.java:662)
11-02 16:41:58.448: E/AndroidRuntime(13702):    at android.os.Parcel.writeValue(Parcel.java:1198)
11-02 16:41:58.448: E/AndroidRuntime(13702):    at android.os.Parcel.writeMapInternal(Parcel.java:591)
11-02 16:41:58.448: E/AndroidRuntime(13702):    at android.os.Bundle.writeToParcel(Bundle.java:1646)
11-02 16:41:58.448: E/AndroidRuntime(13702):    at android.os.Parcel.writeBundle(Parcel.java:605)
11-02 16:41:58.448: E/AndroidRuntime(13702):    at android.os.Parcel.writeValue(Parcel.java:1170)
11-02 16:41:58.448: E/AndroidRuntime(13702):    at android.os.Parcel.writeMapInternal(Parcel.java:591)
11-02 16:41:58.448: E/AndroidRuntime(13702):    at android.os.Bundle.writeToParcel(Bundle.java:1646)
11-02 16:41:58.448: E/AndroidRuntime(13702):    at android.os.Parcel.writeBundle(Parcel.java:605)
11-02 16:41:58.448: E/AndroidRuntime(13702):    at android.os.Parcel.writeValue(Parcel.java:1170)
11-02 16:41:58.448: E/AndroidRuntime(13702):    at android.os.Parcel.writeMapInternal(Parcel.java:591)
11-02 16:41:58.448: E/AndroidRuntime(13702):    at android.os.Bundle.writeToParcel(Bundle.java:1646)
11-02 16:41:58.448: E/AndroidRuntime(13702):    at android.os.Parcel.writeBundle(Parcel.java:605)
11-02 16:41:58.448: E/AndroidRuntime(13702):    at android.os.Parcel.writeValue(Parcel.java:1170)
11-02 16:41:58.448: E/AndroidRuntime(13702):    at android.os.Parcel.writeMapInternal(Parcel.java:591)
11-02 16:41:58.448: E/AndroidRuntime(13702):    at android.os.Bundle.writeToParcel(Bundle.java:1646)
11-02 16:41:58.448: E/AndroidRuntime(13702):    at android.os.Parcel.writeBundle(Parcel.java:605)
11-02 16:41:58.448: E/AndroidRuntime(13702):    at android.os.Parcel.writeValue(Parcel.java:1170)
11-02 16:41:58.448: E/AndroidRuntime(13702):    at android.os.Parcel.writeMapInternal(Parcel.java:591)
11-02 16:41:58.448: E/AndroidRuntime(13702):    at android.os.Bundle.writeToParcel(Bundle.java:1646)
11-02 16:41:58.448: E/AndroidRuntime(13702):    at android.os.Parcel.writeBundle(Parcel.java:605)
11-02 16:41:58.448: E/AndroidRuntime(13702):    at android.os.Parcel.writeValue(Parcel.java:1170)
11-02 16:41:58.448: E/AndroidRuntime(13702):    at android.os.Parcel.writeMapInternal(Parcel.java:591)
11-02 16:41:58.448: E/AndroidRuntime(13702):    at android.os.Bundle.writeToParcel(Bundle.java:1646)
11-02 16:41:58.448: E/AndroidRuntime(13702):    at android.os.Parcel.writeBundle(Parcel.java:605)
11-02 16:41:58.448: E/AndroidRuntime(13702):    at android.os.Parcel.writeValue(Parcel.java:1170)
11-02 16:41:58.448: E/AndroidRuntime(13702):    at android.os.Parcel.writeMapInternal(Parcel.java:591)
11-02 16:41:58.448: E/AndroidRuntime(13702):    at android.os.Bundle.writeToParcel(Bundle.java:1646)
11-02 16:41:58.448: E/AndroidRuntime(13702):    at android.os.Parcel.writeBundle(Parcel.java:605)
11-02 16:41:58.448: E/AndroidRuntime(13702):    at android.os.Parcel.writeValue(Parcel.java:1170)
11-02 16:41:58.448: E/AndroidRuntime(13702):    at android.os.Parcel.writeMapInternal(Parcel.java:591)
11-02 16:41:58.448: E/AndroidRuntime(13702):    at android.os.Bundle.writeToParcel(Bundle.java:1646)
11-02 16:41:58.448: E/AndroidRuntime(13702):    at android.os.Parcel.writeBundle(Parcel.java:605)
11-02 16:41:58.448: E/AndroidRuntime(13702):    at android.os.Parcel.writeValue(Parcel.java:1170)
11-02 16:41:58.448: E/AndroidRuntime(13702):    at android.os.Parcel.writeMapInternal(Parcel.java:591)
11-02 16:41:58.448: E/AndroidRuntime(13702):    at android.os.Bundle.writeToParcel(Bundle.java:1646)
11-02 16:41:58.448: E/AndroidRuntime(13702):    at android.os.Parcel.writeBundle(Parcel.java:605)
11-02 16:41:58.448: E/AndroidRuntime(13702):    at android.os.Parcel.writeValue(Parcel.java:1170)
11-02 16:41:58.448: E/AndroidRuntime(13702):    at android.os.Parcel.writeMapInternal(Parcel.java:591)
11-02 16:41:58.448: E/AndroidRuntime(13702):    at android.os.Bundle.writeToParcel(Bundle.java:1646)
11-02 16:41:58.448: E/AndroidRuntime(13702):    at android.os.Parcel.writeBundle(Parcel.java:605)
11-02 16:41:58.448: E/AndroidRuntime(13702):    at android.os.Parcel.writeValue(Parcel.java:1170)
11-02 16:41:58.448: E/AndroidRuntime(13702):    at android.os.Parcel.writeMapInternal(Parcel.java:591)
11-02 16:41:58.448: E/AndroidRuntime(13702):    at android.os.Bundle.writeToParcel(Bundle.java:1646)
11-02 16:41:58.448: E/AndroidRuntime(13702):    at android.os.Parcel.writeBundle(Parcel.java:605)
11-02 16:41:58.448: E/AndroidRuntime(13702):    at android.os.Parcel.writeValue(Parcel.java:1170)
11-02 16:41:58.448: E/AndroidRuntime(13702):    at android.os.Parcel.writeMapInternal(Parcel.java:591)
11-02 16:41:58.448: E/AndroidRuntime(13702):    at android.os.Bundle.writeToParcel(Bundle.java:1646)
11-02 16:41:58.448: E/AndroidRuntime(13702):    at android.os.Parcel.writeBundle(Parcel.java:605)
11-02 16:41:58.448: E/AndroidRuntime(13702):    at android.os.Parcel.writeValue(Parcel.java:1170)
11-02 16:41:58.448: E/AndroidRuntime(13702):    at android.os.Parcel.writeMapInternal(Parcel.java:591)
11-02 16:41:58.448: E/AndroidRuntime(13702):    at android.os.Bundle.writeToParcel(Bundle.java:1646)
11-02 16:41:58.448: E/AndroidRuntime(13702):    at android.os.Parcel.writeBundle(Parcel.java:605)
11-02 16:41:58.448: E/AndroidRuntime(13702):    at android.os.Parcel.writeValue(Parcel.java:1170)
11-02 16:41:58.448: E/AndroidRuntime(13702):    at android.os.Parcel.writeMapInternal(Parcel.java:591)
11-02 16:41:58.448: E/AndroidRuntime(13702):    at android.os.Bundle.writeToParcel(Bundle.java:1646)
11-02 16:41:58.448: E/AndroidRuntime(13702):    at android.os.Parcel.writeBundle(Parcel.java:605)
11-02 16:41:58.448: E/AndroidRuntime(13702):    at android.os.Parcel.writeValue(Parcel.java:1170)
11-02 16:41:58.448: E/AndroidRuntime(13702):    at android.os.Parcel.writeMapInternal(Parcel.java:591)
11-02 16:41:58.448: E/AndroidRuntime(13702):    at android.os.Bundle.writeToParcel(Bundle.java:1646)
11-02 16:41:58.448: E/AndroidRuntime(13702):    at android.os.Parcel.writeBundle(Parcel.java:605)
11-02 16:41:58.448: E/AndroidRuntime(13702):    at android.os.Parcel.writeValue(Parcel.java:1170)
11-02 16:41:58.448: E/AndroidRuntime(13702):    at android.os.Parcel.writeMapInternal(Parcel.java:591)
11-02 16:41:58.448: E/AndroidRuntime(13702):    at android.os.Bundle.writeToParcel(Bundle.java:1646)
11-02 16:41:58.448: E/AndroidRuntime(13702):    at android.os.Parcel.writeBundle(Parcel.java:605)
11-02 16:41:58.448: E/AndroidRuntime(13702):    at android.os.Parcel.writeValue(Parcel.java:1170)
11-02 16:41:58.448: E/AndroidRuntime(13702):    at android.os.Parcel.writeMapInternal(Parcel.java:591)
11-02 16:41:58.448: E/AndroidRuntime(13702):    at android.os.Bundle.writeToParcel(Bundle.java:1646)
11-02 16:41:58.448: E/AndroidRuntime(13702):    at android.os.Parcel.writeBundle(Parcel.java:605)
11-02 16:41:58.448: E/AndroidRuntime(13702):    at android.os.Parcel.writeValue(Parcel.

我的应用只有 1Activity和 2 TextView、 2Button和 1EditText

@Override
public void onConfigurationChanged(Configuration newConfig) {
    super.onConfigurationChanged(newConfig);
     if (newConfig.orientation == Configuration.ORIENTATION_LANDSCAPE) {
            onSaveInstanceState(newBundy);
        } else if (newConfig.orientation == Configuration.ORIENTATION_PORTRAIT){
            onSaveInstanceState(newBundy);
        }
}

@Override
public void onSaveInstanceState(Bundle outState) {
    super.onSaveInstanceState(outState);
    outState.putBundle("newBundy", newBundy);
}
@Override
protected void onRestoreInstanceState(Bundle savedInstanceState) {
    super.onRestoreInstanceState(savedInstanceState);
    savedInstanceState.getBundle("newBundy");
}

我评论了上面的行,现在没有崩溃,为什么这段代码会导致它崩溃?

4

1 回答 1

0

您实际上不需要保存实例,onConfigurationChanged因为在这种情况下您的活动不会被破坏和重新创建。如果您将捆绑包保存在onSaveInstanceState.

里面的代码onConfigurationChanged可以去掉。

于 2013-11-03T05:50:47.113 回答