Tencent/QMUI_Android · error · RuntimeException

can not perform $action when running.

Error message

can not perform $action when running.

What it means

BaseTypeView.throwIfRunning is a guard the type-rendering view calls before mutating operations: while the view's environment is running (a layout/render pass is in progress), structural changes to the type model are illegal and would corrupt the in-flight pass, so a RuntimeException naming the attempted action is thrown.

Source

Thrown at type/src/main/java/com/qmuiteam/qmui/type/view/BaseTypeView.kt:93

                environment.lineHeight = value
                requestLayout()
            }
        }

    var paragraphSpace: Int
        get() = environment.paragraphSpace
        set(value){
            throwIfRunning("setParagraphSpace")
            if(environment.paragraphSpace != value){
                environment.paragraphSpace = value
                requestLayout()
            }
        }


    fun throwIfRunning(action: String) {
        if(environment.isRunning()){
            throw RuntimeException("can not perform $action when running.")
        }
    }
}

View on GitHub (pinned to 026e7d4866)

Solutions

  1. Defer the mutation until the running pass completes: post it to the view (view.post { ... }) or a handler.
  2. Move the update out of render-pass callbacks into lifecycle points like onAttachedToWindow, data-set changes, or explicit user actions.
  3. Guard your own call sites with environment.isRunning() checks, or call throwIfRunning yourself before mutating to fail fast with a clear action name.

Example fix

// before
void onDataChanged(List<TypeModel> models) {
    typeView.resetData(models); // throws if a render pass is running
}

// after
void onDataChanged(List<TypeModel> models) {
    typeView.post(() -> typeView.resetData(models));
}
Defensive patterns

Strategy: fallback

Validate before calling

if (typeView.getEnvironment().isRunning()) {
    // defer instead of mutating now
    typeView.post(() -> typeView.resetData(models));
    return;
}
typeView.resetData(models);

Try / catch

try {
    typeView.resetData(models);
} catch (RuntimeException e) {
    if (e.getMessage() != null && e.getMessage().contains("when running")) {
        typeView.post(() -> typeView.resetData(models));
    } else {
        throw e;
    }
}

Prevention

When it happens

Trigger: Invoking a BaseTypeView mutating API (e.g. resetting/replacing type models or adding effects) from inside a callback that fires while the view is running — such as during onLayout/onDraw, inside a listener triggered by the rendering pass, or on a callback invoked by the environment's run loop.

Common situations: Updating type content in response to a layout/data-change callback that occurs mid-render; calling invalidate/refill methods from an animation or scroll callback managed by the BaseTypeView itself.

Understand the failure class

Background: "Invalid state transition" errors: "status must be X, actually Y", "already rejected/charging/uninstalled", "cannot ... while running" — what they mean when a library rejects your call — this error's family across 31 libraries.

Related errors


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