{"record":{"id":"8b24f298dad07bc8","repo":"HMCL-dev/HMCL","slug":"main-class-is-null-for-instance","errorCode":null,"errorMessage":"Main class is null for instance ","messagePattern":"Main class is null for instance ","errorType":"exception","errorClass":"IllegalStateException","httpStatus":null,"severity":"critical","filePath":"HMCLCore/src/main/java/org/jackhuang/hmcl/launch/DefaultLauncher.java","lineNumber":354,"sourceCode":"                        }\n                    }\n\n                    break;\n                }\n            }\n        }\n\n        res.addAll(Arguments.parseArguments(Objects.requireNonNullElseGet(jvmArguments, this::getDefaultJVMArguments), configuration));\n        Arguments argumentsFromAuthInfo = authInfo.getLaunchArguments(options);\n        if (argumentsFromAuthInfo != null && argumentsFromAuthInfo.jvm() != null && !argumentsFromAuthInfo.jvm().isEmpty())\n            res.addAll(Arguments.parseArguments(argumentsFromAuthInfo.jvm(), configuration));\n\n        for (String javaAgent : options.getJavaAgents()) {\n            res.add(\"-javaagent:\" + javaAgent);\n        }\n\n        if (manifest.mainClass() == null) {\n            throw new IllegalStateException(\"Main class is null for instance \" + manifest.id());\n        }\n\n        res.add(manifest.mainClass());\n\n        res.addAll(Arguments.parseStringArguments(Optional.ofNullable(manifest.minecraftArguments()).map(StringUtils::tokenize).orElseGet(ArrayList::new), configuration));\n\n        Map<String, Boolean> features = getFeatures();\n        Optional.ofNullable(manifest.arguments()).map(Arguments::game).ifPresent(arguments -> res.addAll(Arguments.parseArguments(arguments, configuration, features)));\n        if (Optional.ofNullable(manifest.minecraftArguments()).isPresent()) {\n            res.addAll(Arguments.parseArguments(this.getDefaultGameArguments(), configuration, features));\n        }\n        if (argumentsFromAuthInfo != null && argumentsFromAuthInfo.game() != null && !argumentsFromAuthInfo.game().isEmpty())\n            res.addAll(Arguments.parseArguments(argumentsFromAuthInfo.game(), configuration, features));\n\n        if (options.getQuickPlayOption() instanceof QuickPlayOption.MultiPlayer multiPlayer) {\n            String address = multiPlayer.serverIP();\n\n            try {","sourceCodeStart":336,"sourceCodeEnd":372,"githubUrl":"https://github.com/HMCL-dev/HMCL/blob/24702dc5a0214034f4c27166d5fd30cad08cec19/HMCLCore/src/main/java/org/jackhuang/hmcl/launch/DefaultLauncher.java#L336-L372","documentation":"DefaultLauncher.generateCommandLine appends the game's main class from the version manifest; if manifest.mainClass() is null the launch command cannot be assembled, so it throws IllegalStateException(\"Main class is null for instance \" + manifest.id()). This indicates a malformed or incomplete version JSON.","triggerScenarios":"Launching an instance whose version manifest (Version JSON) has no mainClass field — e.g. a hand-edited or truncated version file, or a manifest built from an incomplete metadata parse.","commonSituations":"Manually copying version JSONs between installs and dropping fields; corrupted version downloads; custom/third-party version JSONs missing mainClass; version id mismatch causing wrong manifest resolution.","solutions":["Fix the version JSON by adding the correct mainClass (e.g. net.minecraft.client.main.Main) for the version.","Delete the version folder and let the launcher re-download the official version metadata.","If using a custom version, base it on the complete official version JSON rather than editing from scratch.","Verify manifest.id() matches the intended version so the right manifest is loaded."],"exampleFix":"// before (version JSON)\n// { \"id\": \"1.20.1\", \"minecraftArguments\": \"...\" }\n// after\n// { \"id\": \"1.20.1\", \"mainClass\": \"net.minecraft.client.main.Main\", \"minecraftArguments\": \"...\" }","handlingStrategy":"validation","validationCode":"if (manifest.mainClass() == null) {\n    // refuse to launch; repair the version JSON first\n}","typeGuard":null,"tryCatchPattern":"try {\n    launcher.launch();\n} catch (IllegalStateException e) {\n    if (e.getMessage().startsWith(\"Main class is null\")) {\n        // re-download official version metadata for manifest.id()\n    }\n}","preventionTips":["Never hand-edit version JSONs; derive custom versions from complete official ones","Re-download version metadata if files were copied between installs","Validate downloaded version JSON contains mainClass before caching"],"tags":["minecraft","launcher","manifest","missing-field"],"backgroundTag":"missing-required-config-field","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"}