Tencent/QMUI_Android · error · RuntimeException

Can not instance the Class SchemeMapImpl. Please file a issu

Error message

Can not instance the Class SchemeMapImpl. Please file a issue to report this.

What it means

Same reflective init as error 21, but this branch catches InstantiationException: the JVM could not create a new instance of the generated SchemeMapImpl — typically because the class is abstract, an interface, or has no accessible no-arg constructor. Wrapped in a RuntimeException telling you to file an issue.

Source

Thrown at arch/src/main/java/com/qmuiteam/qmui/arch/scheme/QMUISchemeHandler.kt:52

                val cls = Class.forName(SchemeMap::class.java.name + "Impl")
                sSchemeMap = cls.newInstance() as SchemeMap
            } catch (e: ClassNotFoundException) {
                sSchemeMap = object : SchemeMap {
                    override fun findScheme(handler: QMUISchemeHandler, schemeAction: String, params: Map<String, String>?): SchemeItem? {
                        return null
                    }

                    override fun exists(handler: QMUISchemeHandler, schemeAction: String): Boolean {
                        return false
                    }
                }
            } catch (e: IllegalAccessException) {
                throw RuntimeException(
                    "Can not access the Class SchemeMapImpl. " +
                            "Please file a issue to report this."
                )
            } catch (e: InstantiationException) {
                throw RuntimeException(
                    "Can not instance the Class SchemeMapImpl. " +
                            "Please file a issue to report this."
                )
            }
        }
    }

    val prefix: String = builder.prefix
    private var interpolatorList: List<QMUISchemeHandlerInterceptor> = builder.interceptorList
    private val blockSameSchemeTimeout = builder.blockSameSchemeTimeout
    val defaultIntentFactory = builder.defaultIntentFactory
    val defaultFragmentFactory = builder.defaultFragmentFactory
    val defaultSchemeMatcher = builder.defaultSchemeMatcher
    private val fallbackInterceptor = builder.fallbackInterceptor
    private val unKnownSchemeHandler = builder.unKnownSchemeHandler
    private var lastHandledScheme: List<String>? = null
    private var lastSchemeHandledTime: Long = 0

View on GitHub (pinned to 026e7d4866)

Solutions

  1. Clean the build (./gradlew clean) so SchemeMapImpl is regenerated fresh by SchemeProcessor.
  2. Do not hand-edit or replace the generated SchemeMapImpl; re-run annotation processing and use the generated file as-is.
  3. Verify arch and arch-compiler versions match (same release line).
  4. If a fresh build still fails, inspect build/generated SchemeMapImpl for a public no-arg constructor and file an issue with the QMUI project.

Example fix

// before
class SchemeMapImpl private constructor() : ISchemeMap { ... } // hand-edited

// after
// delete hand-written file, clean & rebuild so processor generates:
public class SchemeMapImpl implements ISchemeMap { public SchemeMapImpl() { ... } }
Defensive patterns

Strategy: try-catch

Validate before calling

try {
    val c = Class.forName("com.qmuiteam.qmui.arch.scheme.SchemeMapImpl")
    check(!c.isInterface && !java.lang.reflect.Modifier.isAbstract(c.modifiers)) { "SchemeMapImpl not instantiable" }
    c.getDeclaredConstructor().newInstance()
} catch (e: Throwable) {
    Log.e(TAG, "SchemeMapImpl cannot be instantiated — clean & rebuild", e)
}

Type guard

fun isSchemeMapInstantiable(): Boolean = runCatching {
    val c = Class.forName("com.qmuiteam.qmui.arch.scheme.SchemeMapImpl")
    !c.isInterface && !java.lang.reflect.Modifier.isAbstract(c.modifiers)
}.getOrDefault(false)

Try / catch

try {
    QMUISchemeHandler.instance.handle(uri)
} catch (e: RuntimeException) {
    if (e.message?.contains("Can not instance the Class SchemeMapImpl") == true) {
        Log.e(TAG, "regenerate SchemeMapImpl: clean build, remove hand-edits", e)
    } else throw e
}

Prevention

When it happens

Trigger: Accessing QMUISchemeHandler when SchemeMapImpl was generated as abstract/non-instantiable, the generated class is corrupted or manually replaced, or an old generated file without a public no-arg constructor lingers in the build.

Common situations: Stale generated sources after compiler/plugin upgrades; manually edited or hand-written SchemeMapImpl; build cache corruption; annotation processor version mismatch producing incompatible generated code.

Related errors


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