Tencent/QMUI_Android · error · RuntimeException

Can not find the fragment container provider.

Error message

Can not find the fragment container provider.

What it means

startFragmentAndDestroyCurrent needs a QMUIFragmentContainerProvider (normally the hosting QMUIFragmentActivity) to obtain the container FragmentManager. When none is found the library throws in DEBUG builds (and only logs/returns -1 in release).

Source

Thrown at arch/src/main/java/com/qmuiteam/qmui/arch/QMUIFragment.java:382

     * fragment D and destroy fragment C. Now you are in fragment D, if you want call
     * {@link #popBackStack()} to back to B, what the animation should be? Sometimes we hope run
     * animation generated by transition B->C, but sometimes we hope run animation generated by
     * transition C->D. this why second parameter exists.
     *
     * @param fragment                      new fragment to start
     * @param useNewTransitionConfigWhenPop if true, use animation generated by transition C->D,
     *                                      else, use animation generated by transition B->C
     */
    public int startFragmentAndDestroyCurrent(QMUIFragment fragment,
                                                 boolean useNewTransitionConfigWhenPop) {
        if (!checkStateLoss("startFragmentAndDestroyCurrent")) {
            return -1;
        }

        QMUIFragmentContainerProvider provider = findFragmentContainerProvider(true);
        if (provider == null) {
            if (QMUIConfig.DEBUG) {
                throw new RuntimeException("Can not find the fragment container provider.");
            } else {
                Log.d(TAG, "Can not find the fragment container provider.");
                return -1;
            }
        }

        if(provider.getContainerFragmentManager().isDestroyed()){
            return -1;
        }

        QMUIFragment.TransitionConfig transitionConfig = fragment.onFetchTransitionConfig();
        String tagName = fragment.getClass().getSimpleName();
        FragmentManager fragmentManager = provider.getContainerFragmentManager();
        FragmentTransaction transaction = fragmentManager.beginTransaction()
                .setCustomAnimations(
                        transitionConfig.enter, transitionConfig.exit,
                        transitionConfig.popenter, transitionConfig.popout)
                .setPrimaryNavigationFragment(null)

View on GitHub (pinned to 026e7d4866)

Solutions

  1. Host fragments inside QMUIFragmentActivity (which implements QMUIFragmentContainerProvider)
  2. Make the host activity implement QMUIFragmentContainerProvider and return a valid FragmentManager/container id
  3. Ensure the fragment is attached before calling startFragmentAndDestroyCurrent

Example fix

// before
public class MainActivity extends AppCompatActivity {}
// after
public class MainActivity extends QMUIFragmentActivity {}
Defensive patterns

Strategy: validation

Validate before calling

if (isAdded() && getActivity() instanceof QMUIFragmentContainerProvider) { startFragmentAndDestroyCurrent(target); }

Type guard

boolean hasContainerProvider(Fragment f) { return f.getActivity() instanceof QMUIFragmentContainerProvider; }

Prevention

When it happens

Trigger: Calling startFragmentAndDestroyCurrent from a QMUIFragment hosted in an activity that does not implement QMUIFragmentContainerProvider, or before the fragment is attached.

Common situations: Hosting QMUIFragment inside a non-QMUI activity (plain FragmentActivity/AppCompatActivity), nested fragments whose parent activity chain lacks the provider, calling from a detached fragment.

Understand the failure class

Background: 'Could not be found', 'does not exist', 'not found in database': the resource-not-found family when an ID, slug, key, or URI lookup comes back empty — this error's family across 20 libraries.

Related errors


AI-assisted analysis of Tencent/QMUI_Android@026e7d4866 (2026-09-06). Data as JSON: /api/errors/a703a6be1f2cb93a. Report an issue: GitHub.