libgdx/libgdx · error · ReflectionException

Constructor not found for class:

Error message

Constructor not found for class: 

What it means

getConstructor(Class c, Class... parameterTypes) could not find a public constructor of c matching the exact parameter types given; gwtref threw NoSuchMethodException and it is rethrown as ReflectionException with the class name. Under GWT the lookup is against the generated reflection data, so a constructor can be 'missing' both because it truly does not exist and because its parameter types were not emitted.

Source

Thrown at backends/gdx-backends-gwt/src/com/badlogic/gdx/backends/gwt/emu/com/badlogic/gdx/utils/reflect/ClassReflection.java:129

	 * Class. */
	static public Constructor[] getConstructors (Class c) {
		com.badlogic.gwtref.client.Constructor[] constructors = ReflectionCache.getType(c).getConstructors();
		Constructor[] result = new Constructor[constructors.length];
		for (int i = 0, j = constructors.length; i < j; i++) {
			result[i] = new Constructor(constructors[i]);
		}
		return result;
	}

	/** Returns a {@link Constructor} that represents the public constructor for the supplied class which takes the supplied
	 * parameter types. */
	static public Constructor getConstructor (Class c, Class... parameterTypes) throws ReflectionException {
		try {
			return new Constructor(ReflectionCache.getType(c).getConstructor(parameterTypes));
		} catch (SecurityException e) {
			throw new ReflectionException("Security violation while getting constructor for class: " + c.getName(), e);
		} catch (NoSuchMethodException e) {
			throw new ReflectionException("Constructor not found for class: " + c.getName(), e);
		}
	}

	/** Returns a {@link Constructor} that represents the constructor for the supplied class which takes the supplied parameter
	 * types. */
	static public Constructor getDeclaredConstructor (Class c, Class... parameterTypes) throws ReflectionException {
		try {
			return new Constructor(ReflectionCache.getType(c).getDeclaredConstructor(parameterTypes));
		} catch (SecurityException e) {
			throw new ReflectionException("Security violation while getting constructor for class: " + c.getName(), e);
		} catch (NoSuchMethodException e) {
			throw new ReflectionException("Constructor not found for class: " + c.getName(), e);
		}
	}

	/** Returns the elements of this enum class or null if this Class object does not represent an enum type. */
	static public Object[] getEnumConstants (Class c) {
		return ReflectionCache.getType(c).getEnumConstants();

View on GitHub (pinned to 97f4086187)

Solutions

  1. Match the exact declared parameter types, including primitives (float.class not Float.class).
  2. Add the class and all parameter types to gdx.reflect.include and recompile the GWT module.
  3. Verify with getConstructors() in a debug build what gwtref actually exposes for the class.

Example fix

// before
Constructor c = ClassReflection.getConstructor(Vec.class, Float.class); // no match

// after
Constructor c = ClassReflection.getConstructor(Vec.class, float.class);
Defensive patterns

Strategy: try-catch

Validate before calling

static boolean hasPublicConstructor (Class<?> c, Class<?>... params) {
    for (Constructor ctor : ClassReflection.getConstructors(c)) {
        Class<?>[] p = ctor.getParameterTypes();
        if (java.util.Arrays.equals(p, params)) return true;
    }
    return false;
}

Try / catch

try { ctor = ClassReflection.getConstructor(c, params); }
catch (ReflectionException e) { throw new IllegalStateException("missing ctor on " + c.getName()
    + " with " + java.util.Arrays.toString(params) + "; declared: "
    + java.util.Arrays.toString(ClassReflection.getDeclaredConstructors(c)), e); }

Prevention

When it happens

Trigger: Passing wrong parameter types (e.g. wrapper vs primitive: Integer.class instead of float.class, or int.class vs Integer.class); requesting an inherited constructor (constructors are never inherited); the class or its parameter types missing from gdx.reflect.include.

Common situations: Serialization frameworks resolving deserialization constructors on GWT; refactoring a constructor signature while callers still look up the old parameter list.

Related errors


AI-assisted analysis of libgdx/libgdx@97f4086187 (2026-08-14). Data as JSON: /api/errors/02cb9d52c858e265. Report an issue: GitHub.