didi/DoKit · error · NoSuchMethodException

No similar method ${name} with params ${types} could be foun

Error message

No similar method ${name} with params ${types} could be found on type ${type}.

What it means

ReflectUtils.similarMethod(name, types) walks the class hierarchy comparing declared methods with isSimilarSignature (name match plus boxed-type-compatible parameters). If no class in the chain declares a matching method, it throws NoSuchMethodException with the method name, parameter types and originating type. 'Similar' means parameter types are compared leniently (primitives vs wrappers), but the method name must match exactly and accessibility is not considered at this stage.

Source

Thrown at Android/dokit-util/src/main/java/com/didichuxing/doraemonkit/util/ReflectUtils.java:361

        }
        if (!methods.isEmpty()) {
            sortMethods(methods);
            return methods.get(0);
        }
        do {
            for (Method method : type.getDeclaredMethods()) {
                if (isSimilarSignature(method, name, types)) {
                    methods.add(method);
                }
            }
            if (!methods.isEmpty()) {
                sortMethods(methods);
                return methods.get(0);
            }
            type = type.getSuperclass();
        } while (type != null);

        throw new NoSuchMethodException("No similar method " + name + " with params "
                + Arrays.toString(types) + " could be found on type " + type() + ".");
    }

    private void sortMethods(final List<Method> methods) {
        Collections.sort(methods, new Comparator<Method>() {
            @Override
            public int compare(Method o1, Method o2) {
                Class<?>[] types1 = o1.getParameterTypes();
                Class<?>[] types2 = o2.getParameterTypes();
                int len = types1.length;
                for (int i = 0; i < len; i++) {
                    if (!types1[i].equals(types2[i])) {
                        if (wrapper(types1[i]).isAssignableFrom(wrapper(types2[i]))) {
                            return 1;
                        } else {
                            return -1;
                        }
                    }

View on GitHub (pinned to 626827cddb)

Solutions

  1. Verify the method name spelled exactly and parameter types/arity against the target class (javap or the source).
  2. Add proguard/R8 keep rules for classes accessed via ReflectUtils.
  3. Pass wrapper types matching the declared signature, or use the no-arg method(...) variant when applicable.
  4. Catch NoSuchMethodException and degrade gracefully if the reflected API is optional.

Example fix

// before
Method m = ReflectUtils.on(view).reflect().method("setTex", CharSequence.class).get();

// after
Method m = ReflectUtils.on(view).reflect().method("setText", CharSequence.class).get();
Defensive patterns

Strategy: try-catch

Validate before calling

boolean exists = false;
for (Method m : targetClass.getMethods()) {
    if (m.getName().equals(name) && m.getParameterCount() == expectedArity) { exists = true; break; }
}

Try / catch

try {
    Method m = ReflectUtils.on(obj).reflect().method("setText", CharSequence.class).get();
} catch (NoSuchMethodException e) {
    // optional API absent: degrade gracefully, log once
}

Prevention

When it happens

Trigger: Calling reflect().method("toString", ...) misspelled (e.g. "tostring"); passing wrong arity or incompatible parameter types; target method living in an interface rather than a class (getDeclaredMethods on the implementing class still shows it, but a proxy-only type may not); calling before the right class loader loaded the class.

Common situations: Version changes of a third-party library renaming or removing a reflected method (classic proguard/R8 issue — reflection breaking after minification); wrong parameter boxing (passing Integer where double is expected); invoking on the wrong type variable after refactoring.

Related errors


AI-assisted analysis of didi/DoKit@626827cddb (2026-08-14). Data as JSON: /api/errors/e953ea4067e4fd34. Report an issue: GitHub.