美文网首页
java.lang.StackOverflowError: st

java.lang.StackOverflowError: st

作者: 王魔王 | 来源:发表于2019-11-22 08:55 被阅读0次

在使用Fragment的时候,无意间会发生这个异常

 java.lang.StackOverflowError: stack size 8MB
        at android.view.ViewGroup.jumpDrawablesToCurrentState(ViewGroup.java:5901)
        at android.view.ViewGroup.jumpDrawablesToCurrentState(ViewGroup.java:5905)
        at android.widget.FrameLayout.jumpDrawablesToCurrentState(FrameLayout.java:224)
        at android.view.ViewGroup.jumpDrawablesToCurrentState(ViewGroup.java:5905)
        at android.view.ViewGroup.jumpDrawablesToCurrentState(ViewGroup.java:5905)
        at android.view.ViewGroup.jumpDrawablesToCurrentState(ViewGroup.java:5905)
        at android.view.ViewGroup.jumpDrawablesToCurrentState(ViewGroup.java:5905)
        at android.view.ViewGroup.jumpDrawablesToCurrentState(ViewGroup.java:5905)
        at android.view.ViewGroup.jumpDrawablesToCurrentState(ViewGroup.java:5905)
        at android.view.ViewGroup.jumpDrawablesToCurrentState(ViewGroup.java:5905)
        at android.view.ViewGroup.jumpDrawablesToCurrentState(ViewGroup.java:5905)
        at android.view.ViewGroup.jumpDrawablesToCurrentState(ViewGroup.java:5905)
        at android.view.ViewGroup.jumpDrawablesToCurrentState(ViewGroup.java:5905)

那么检查你的onCreateView()中的代码,看看View的初始化是不是写成了下面这样👇

  @Override
    public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        View rootView = inflater.inflate(R.layout.fragment_home,container,true);
        return rootView;
    }

注意,View初始化的时候不能传true,把true改成false就好了
正确代码示例

@Override
    public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        View rootView = inflater.inflate(R.layout.fragment_home,container,false);
        return rootView;
    }

相关文章

网友评论

      本文标题:java.lang.StackOverflowError: st

      本文链接:https://www.haomeiwen.com/subject/fwhfwctx.html