java.lang.StackOverflowError: st

2019-11-22  本文已影响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;
    }
上一篇 下一篇

猜你喜欢

热点阅读