{"record":{"id":"02cb9d52c858e265","repo":"libgdx/libgdx","slug":"constructor-not-found-for-class","errorCode":null,"errorMessage":"Constructor not found for class: ","messagePattern":"Constructor not found for class: ","errorType":"exception","errorClass":"ReflectionException","httpStatus":null,"severity":"error","filePath":"backends/gdx-backends-gwt/src/com/badlogic/gdx/backends/gwt/emu/com/badlogic/gdx/utils/reflect/ClassReflection.java","lineNumber":129,"sourceCode":"\t * Class. */\n\tstatic public Constructor[] getConstructors (Class c) {\n\t\tcom.badlogic.gwtref.client.Constructor[] constructors = ReflectionCache.getType(c).getConstructors();\n\t\tConstructor[] result = new Constructor[constructors.length];\n\t\tfor (int i = 0, j = constructors.length; i < j; i++) {\n\t\t\tresult[i] = new Constructor(constructors[i]);\n\t\t}\n\t\treturn result;\n\t}\n\n\t/** Returns a {@link Constructor} that represents the public constructor for the supplied class which takes the supplied\n\t * parameter types. */\n\tstatic public Constructor getConstructor (Class c, Class... parameterTypes) throws ReflectionException {\n\t\ttry {\n\t\t\treturn new Constructor(ReflectionCache.getType(c).getConstructor(parameterTypes));\n\t\t} catch (SecurityException e) {\n\t\t\tthrow new ReflectionException(\"Security violation while getting constructor for class: \" + c.getName(), e);\n\t\t} catch (NoSuchMethodException e) {\n\t\t\tthrow new ReflectionException(\"Constructor not found for class: \" + c.getName(), e);\n\t\t}\n\t}\n\n\t/** Returns a {@link Constructor} that represents the constructor for the supplied class which takes the supplied parameter\n\t * types. */\n\tstatic public Constructor getDeclaredConstructor (Class c, Class... parameterTypes) throws ReflectionException {\n\t\ttry {\n\t\t\treturn new Constructor(ReflectionCache.getType(c).getDeclaredConstructor(parameterTypes));\n\t\t} catch (SecurityException e) {\n\t\t\tthrow new ReflectionException(\"Security violation while getting constructor for class: \" + c.getName(), e);\n\t\t} catch (NoSuchMethodException e) {\n\t\t\tthrow new ReflectionException(\"Constructor not found for class: \" + c.getName(), e);\n\t\t}\n\t}\n\n\t/** Returns the elements of this enum class or null if this Class object does not represent an enum type. */\n\tstatic public Object[] getEnumConstants (Class c) {\n\t\treturn ReflectionCache.getType(c).getEnumConstants();","sourceCodeStart":111,"sourceCodeEnd":147,"githubUrl":"https://github.com/libgdx/libgdx/blob/97f40861878058087be0685ca167ddfde132134b/backends/gdx-backends-gwt/src/com/badlogic/gdx/backends/gwt/emu/com/badlogic/gdx/utils/reflect/ClassReflection.java#L111-L147","documentation":"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.","triggerScenarios":"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.","commonSituations":"Serialization frameworks resolving deserialization constructors on GWT; refactoring a constructor signature while callers still look up the old parameter list.","solutions":["Match the exact declared parameter types, including primitives (float.class not Float.class).","Add the class and all parameter types to gdx.reflect.include and recompile the GWT module.","Verify with getConstructors() in a debug build what gwtref actually exposes for the class."],"exampleFix":"// before\nConstructor c = ClassReflection.getConstructor(Vec.class, Float.class); // no match\n\n// after\nConstructor c = ClassReflection.getConstructor(Vec.class, float.class);","handlingStrategy":"try-catch","validationCode":"static boolean hasPublicConstructor (Class<?> c, Class<?>... params) {\n    for (Constructor ctor : ClassReflection.getConstructors(c)) {\n        Class<?>[] p = ctor.getParameterTypes();\n        if (java.util.Arrays.equals(p, params)) return true;\n    }\n    return false;\n}","typeGuard":null,"tryCatchPattern":"try { ctor = ClassReflection.getConstructor(c, params); }\ncatch (ReflectionException e) { throw new IllegalStateException(\"missing ctor on \" + c.getName()\n    + \" with \" + java.util.Arrays.toString(params) + \"; declared: \"\n    + java.util.Arrays.toString(ClassReflection.getDeclaredConstructors(c)), e); }","preventionTips":["Use primitive class literals (int.class, float.class) for primitive parameters.","Update reflection lookups whenever constructor signatures change.","Ensure the class is in gdx.reflect.include for GWT builds."],"tags":["reflection","gwt","constructor","signature-mismatch","libgdx"],"backgroundTag":null,"analyzedSha":"97f40861878058087be0685ca167ddfde132134b","analyzedAt":"2026-08-14T10:52:53.492Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}