Tencent/QMUI_Android · error · RuntimeException

requestCode can not be %s

Error message

requestCode can not be %s

What it means

Thrown by a generic input guard at the top of the deprecated startFragmentForResult method: before launching the target fragment, the method validates its requestCode argument against the NO_REQUEST_CODE sentinel constant and throws a RuntimeException if they are equal. NO_REQUEST_CODE is the internal marker reserved for fragments that were NOT started for a result, so a caller passing it would make the later onFragmentResult dispatch impossible to route back. The error therefore means the caller invoked startFragmentForResult with the reserved sentinel value (typically the default/uninitialized requestCode) instead of a unique caller-defined request code, and the faulting input is the requestCode parameter.

Source

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

    /**
     * simulate the behavior of startActivityForResult/onActivityResult:
     * 1. Jump fragment1 to fragment2 via startActivityForResult(fragment2, requestCode)
     * 2. Pass data from fragment2 to fragment1 via setFragmentResult(RESULT_OK, data)
     * 3. Get data in fragment1 through onFragmentResult(requestCode, resultCode, data)
     *
     * @deprecated use {@link #registerEffect} for a replacement
     *
     * @param fragment    target fragment
     * @param requestCode request code
     */
    @Deprecated
    public int startFragmentForResult(QMUIFragment fragment, int requestCode) {
        if (!checkStateLoss("startFragmentForResult")) {
            return -1;
        }
        if (requestCode == NO_REQUEST_CODE) {
            throw new RuntimeException("requestCode can not be " + NO_REQUEST_CODE);
        }
        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;
            }
        }

        mSourceRequestCode = requestCode;
        fragment.mTargetFragmentUUid = mUUid;
        fragment.mTargetRequestCode = requestCode;
        return startFragment(fragment, provider);
    }

    private int startFragment(QMUIFragment fragment, QMUIFragmentContainerProvider provider) {

View on GitHub (pinned to 026e7d4866)

Solutions

  1. Use a positive requestCode (e.g. 1, 2, ...) distinct from NO_REQUEST_CODE
  2. Migrate off the deprecated overload to the current startFragmentForResult API
  3. Define app constants for request codes to avoid accidental sentinel usage

Example fix

// before
startFragmentForResult(fragment, -1);
// after
startFragmentForResult(fragment, 1001);
Defensive patterns

Strategy: validation

Validate before calling

if (requestCode != QMUIFragment.NO_REQUEST_CODE) { startFragmentForResult(fragment, requestCode); }

Prevention

When it happens

Trigger: Calling the deprecated startFragmentForResult(fragment, requestCode) with requestCode equal to NO_REQUEST_CODE (the library's reserved sentinel, typically -1).

Common situations: Passing -1 as a 'default' requestCode; copying code from startFragment and reusing sentinel constants; calling the deprecated overload instead of the newer API.

Understand the failure class

Background: "Must be a positive integer", "Invalid value", "Unsupported": the invalid-argument-value error family, when a library rejects the value you pass — this error's family across 35 libraries.

Related errors


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