{"record":{"id":"06c28262cdfca90e","repo":"apache/flink","slug":"the-class-s-has-no-main-string-method","errorCode":null,"errorMessage":"The class %s has no main(String[]) method.","messagePattern":"The class (.+?) has no main\\(String\\[\\]\\) method\\.","errorType":"exception","errorClass":"ProgramInvocationException","httpStatus":null,"severity":"error","filePath":"flink-clients/src/main/java/org/apache/flink/client/program/PackagedProgram.java","lineNumber":338,"sourceCode":"                    t);\n        }\n\n        return Modifier.isStatic(mainMethod.getModifiers())\n                && Modifier.isPublic(mainMethod.getModifiers());\n    }\n\n    private static void callMainMethod(Class<?> entryClass, String[] args)\n            throws ProgramInvocationException {\n        Method mainMethod;\n        if (!Modifier.isPublic(entryClass.getModifiers())) {\n            throw new ProgramInvocationException(\n                    \"The class \" + entryClass.getName() + \" must be public.\");\n        }\n\n        try {\n            mainMethod = entryClass.getMethod(\"main\", String[].class);\n        } catch (NoSuchMethodException e) {\n            throw new ProgramInvocationException(\n                    \"The class \" + entryClass.getName() + \" has no main(String[]) method.\");\n        } catch (Throwable t) {\n            throw new ProgramInvocationException(\n                    \"Could not look up the main(String[]) method from the class \"\n                            + entryClass.getName()\n                            + \": \"\n                            + t.getMessage(),\n                    t);\n        }\n\n        if (!Modifier.isStatic(mainMethod.getModifiers())) {\n            throw new ProgramInvocationException(\n                    \"The class \" + entryClass.getName() + \" declares a non-static main method.\");\n        }\n        if (!Modifier.isPublic(mainMethod.getModifiers())) {\n            throw new ProgramInvocationException(\n                    \"The class \" + entryClass.getName() + \" declares a non-public main method.\");\n        }","sourceCodeStart":320,"sourceCodeEnd":356,"githubUrl":"https://github.com/apache/flink/blob/2f3c205e9266cb30240eb7f4fdab15cad629a70f/flink-clients/src/main/java/org/apache/flink/client/program/PackagedProgram.java#L320-L356","documentation":"Thrown by callMainMethod when entryClass.getMethod(\"main\", String[].class) raises NoSuchMethodException. Note this is a separate check from the earlier hasMainMethod call: the constructor gates on hasMainMethod, but callMainMethod re-validates at invocation time, so this fires if the class lost its main method between construction and invocation, or callMainMethod is called on a different class than was validated.","triggerScenarios":"callMainMethod is invoked on a class whose getMethod(\"main\", String[].class) returns no method. This is essentially the same condition as error 61 but reported at invoke time.","commonSituations":"A program class loaded at construction differs from the one used at invocation (e.g. multiple classloaders), or the main method was removed/renamed between build steps.","solutions":["Ensure the entry class defines 'public static void main(String[])'.","Verify the exact signature: parameter must be String[] (not String... or Object[]).","Check that the classloader used at invocation matches the one at PackagedProgram construction."],"exampleFix":"// before\npublic class MyJob {\n    public static void main(String args) { ... } // wrong signature\n}\n\n// after\npublic class MyJob {\n    public static void main(String[] args) throws Exception { ... }\n}","handlingStrategy":"validation","validationCode":"boolean hasMain;\ntry {\n    Method m = entryClass.getMethod(\"main\", String[].class);\n    hasMain = Modifier.isPublic(m.getModifiers()) && Modifier.isStatic(m.getModifiers());\n} catch (NoSuchMethodException e) {\n    hasMain = false;\n}\nif (!hasMain) throw new IllegalArgumentException(\"Missing public static main(String[])\");","typeGuard":null,"tryCatchPattern":"try {\n    packagedProgram.invokeInteractiveModeForExecution();\n} catch (ProgramInvocationException pie) {\n    if (pie.getMessage().contains(\"has no main(String[])\")) {\n        // fix signature / rebuild jar\n    }\n    throw pie;\n}","preventionTips":["Pin the exact signature 'public static void main(String[] args)'.","Avoid varargs (String...) — they compile to String[] but can confuse tooling.","Verify with javap that the class exposes main(String[])."],"tags":["packaged-program","main-method","invocation"],"backgroundTag":null,"analyzedSha":"2f3c205e9266cb30240eb7f4fdab15cad629a70f","analyzedAt":"2026-08-14T08:48:24.518Z","schemaVersion":2},"datasetVersion":"2026-08-14T10:17:34.591Z"}