我知道这种类型的错误存在一些问题,但我的问题是随机发生的,我还没有找到导致它的原因。这是错误日志:
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.
我的应用只有1 Activity
只有2 TextView
,2 Button
和1 EditText
@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");
}
我评论了上面的行,现在没有崩溃,为什么这段代码会崩溃?
答案 0 :(得分:0)
您实际上不需要在onConfigurationChanged
中保存实例,因为在这种情况下您的活动不会被销毁并重新创建。如果您将捆绑包保存在onSaveInstanceState
中就足够了。
onConfigurationChanged
中的代码可以删除。