{"record":{"id":"f97e8f86403ff831","repo":"HMCL-dev/HMCL","slug":"cannot-find-method-main-string-in-mainclass","errorCode":null,"errorMessage":"Cannot find method 'main(String[])' in ${mainClass}","messagePattern":"Cannot find method 'main\\(String\\[\\]\\)' in (.+?)","errorType":"console","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"critical","filePath":"minecraft/libraries/HMCLMultiMCBootstrap/src/main/java/org/jackhuang/hmcl/HMCLMultiMCBootstrap.java","lineNumber":85,"sourceCode":"        System.out.println(installerInfo);\n        System.out.println(\"Main Class: \" + mainClass);\n        System.out.println(\"GAME MAY CRASH DUE TO BUGS. TEST YOUR GAME ON OFFICIAL MMC BEFORE REPORTING BUGS TO AUTHORS.\");\n\n        Method[] methods = Class.forName(mainClass).getMethods();\n        for (Method method : methods) {\n            // https://docs.oracle.com/javase/specs/jls/se21/html/jls-12.html#jls-12.1.4\n            if (\"main\".equals(method.getName()) &&\n                    Modifier.isStatic(method.getModifiers()) &&\n                    method.getReturnType() == void.class &&\n                    method.getParameterCount() == 1 &&\n                    method.getParameters()[0].getType() == String[].class\n            ) {\n                method.invoke(null, (Object) args);\n                return;\n            }\n        }\n\n        throw new IllegalArgumentException(\"Cannot find method 'main(String[])' in \" + mainClass);\n    }\n\n    private static Map<String, String> parseQuery(String queryParameterString) {\n        if (queryParameterString == null) return Collections.emptyMap();\n\n        Map<String, String> result = new HashMap<>();\n\n        try (Scanner scanner = new Scanner(queryParameterString)) {\n            scanner.useDelimiter(\"&\");\n            while (scanner.hasNext()) {\n                String[] nameValue = scanner.next().split(\"=\");\n                if (nameValue.length == 0 || nameValue.length > 2) {\n                    throw new IllegalArgumentException(\"bad query string\");\n                }\n\n                String name = decodeURL(nameValue[0]);\n                String value = nameValue.length == 2 ? decodeURL(nameValue[1]) : null;\n                result.put(name, value);","sourceCodeStart":67,"sourceCodeEnd":103,"githubUrl":"https://github.com/HMCL-dev/HMCL/blob/24702dc5a0214034f4c27166d5fd30cad08cec19/minecraft/libraries/HMCLMultiMCBootstrap/src/main/java/org/jackhuang/hmcl/HMCLMultiMCBootstrap.java#L67-L103","documentation":"`HMCLMultiMCBootstrap.launch` throws `IllegalArgumentException(\"Cannot find method 'main(String[])' in \" + mainClass)` after reflectively loading the configured main class and scanning its public methods: no static void method named `main` accepting exactly one `String[]` parameter exists. This bootstrap launches MultiMC/Prism instance-installed games by delegating to the real main class; without a spec-compliant `main(String[])` the launch cannot proceed (JLS 12.1.4).","triggerScenarios":"Setting the `main_class` query parameter in the bootstrap_profile_v1 URI, or the base64 `hmcl.mmc.bootstrap.main` system property, to a class that: has no `main` method at all, has `main` with a wrong signature (`main(String)` single String, non-static, returns non-void, or varargs-only non-public variants — note `getMethods()` only returns public methods), or points to a library class rather than an entry point. `Class.forName` succeeding but the shape check failing is exactly this error.","commonSituations":"Modpack/instance configs where `main_class` was hand-edited or generated for a different bootstrap (e.g. a class with `public static void main(String[] args)` made package-private), Fabric/Forge installer updates changing the entry-point class, or typos in the main class name pointing to an unrelated class.","solutions":["Verify `mainClass` names a class with exactly `public static void main(String[] args)`; print the value logged at launch ('Main Class: ...') and check it.","If the class has a non-standard entry point, invoke that class's own launcher mechanism instead of this bootstrap, or add a compliant main wrapper.","Check that the modpack template's `main_class` matches the loader version actually installed (e.g. correct Forge/Fabric main class for that Minecraft version).","Reinstall the version via HMCL so it writes the correct bootstrap configuration."],"exampleFix":"// before (instance config / query)\nmain_class=com.example.mod.Launcher   // has only: static void main(String arg)\n// after\nmain_class=com.example.mod.Main       // public static void main(String[] args)\n// or add a wrapper in the target class:\npublic static void main(String[] args) { new Launcher().launch(String.join(\" \", args)); }","handlingStrategy":"try-catch","validationCode":"static void validateMainClass(String mainClass) throws Exception {\n    Class<?> c = Class.forName(mainClass);\n    for (Method m : c.getMethods()) {\n        if (\"main\".equals(m.getName()) && Modifier.isStatic(m.getModifiers())\n                && m.getReturnType() == void.class && m.getParameterCount() == 1\n                && m.getParameterTypes()[0] == String[].class) {\n            return; // OK\n        }\n    }\n    throw new IllegalArgumentException(\"No public static void main(String[]) in \" + mainClass);\n}","typeGuard":null,"tryCatchPattern":"try {\n    launch(installerInfo, mainClass, args);\n} catch (IllegalArgumentException e) {\n    System.err.println(\"Bootstrap failed: \" + e.getMessage());\n    System.err.println(\"Check main_class in the instance bootstrap profile.\");\n    System.exit(1);\n} catch (ClassNotFoundException e) {\n    System.err.println(\"Main class not found: \" + mainClass);\n    System.exit(1);\n}","preventionTips":["Always confirm the configured main class declares public static void main(String[] args) exactly.","Keep main_class in sync with the loader (Forge/Fabric) version installed in the instance.","Remember getMethods() only sees public methods — package-private main will fail.","Log the resolved mainClass at launch so misconfiguration is immediately visible."],"tags":["java","reflection","bootstrap","entrypoint","multimc"],"backgroundTag":"missing-required-argument","analyzedSha":"24702dc5a0214034f4c27166d5fd30cad08cec19","analyzedAt":"2026-09-10T12:36:46.680Z","contentChangedAt":"2026-09-10T12:36:46.680Z","schemaVersion":2},"datasetVersion":"2026-09-15T23:17:13.987Z"}