IllegalStateException: Fragment DetailFragment did not return a View from onCreateView() or this was called before onCreateView()

I got a weird error:

java.lang.IllegalStateException: Fragment DetailFragment{478548c} (790a9d4b-aae5-425a-a41d-2ab5785e5479) id=0x7f0b1c79 DetailFragment} did not return a View from onCreateView() or this was called before onCreateView().
at androidx.fragment.app.Fragment.requireView(SourceFile:1781)
at androidx.fragment.app.FragmentTransition.captureOutSharedElements(SourceFile:846)
at androidx.fragment.app.FragmentTransition.configureSharedElementsOrdered(SourceFile:758)
at androidx.fragment.app.FragmentTransition.configureTransitionsOrdered(SourceFile:378)
at androidx.fragment.app.FragmentTransition.startTransitions(SourceFile:155)
at androidx.fragment.app.FragmentManager.executeOpsTogether(SourceFile:2001)
at androidx.fragment.app.FragmentManager.removeRedundantOperationsAndExecute(SourceFile:1959)
at androidx.fragment.app.FragmentManager.execPendingActions(SourceFile:1861)
at androidx.fragment.app.FragmentManager$4.run(SourceFile:413)
at android.os.Handler.handleCallback(Handler.java:907)
at android.os.Handler.dispatchMessage(Handler.java:105)
at android.os.Looper.loop(Looper.java:216)
at android.app.ActivityThread.main(ActivityThread.java:7625)
at java.lang.reflect.Method.invoke(Method.java)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:524)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:987)

The error occurred till now only 3 times on different devices. It’s really seldom compared to usage of the app. And I cannot reproduce it. According to our tracking it occured when the user pressed back on this Fragment. This fragment doesn’t override the onBackPressed() but the parent overrides it and there is nothing what can help me to recognise the problem:

public boolean onBackPressed() {
    return false;
}

so I have no idea where to search the bug.

EDIT: this fragment also doesn’t override onCreateView(), it does the parent:

    @Nullable
@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container,
                         @Nullable Bundle savedInstanceState) {

    dataBinding = inflateBinding(inflater, container);
    initViews();

    if (firstStart) {
        onFirstCreateView();
    } else {
        onReCreateView(savedInstanceState);
    }
    firstStart = false;

    return dataBinding.getRoot();
}

Source: Android Questions

One Reply to “IllegalStateException: Fragment DetailFragment did not return a View from onCreateView() or this was called before onCreateView()”

LEAVE A COMMENT