{"record":{"id":"c529c56f544a5394","repo":"JetBrains/intellij-community","slug":"no-main-class-specified","errorCode":null,"errorMessage":"No main class specified","messagePattern":"No main class specified","errorType":"validation","errorClass":"RuntimeConfigurationError","httpStatus":null,"severity":"error","filePath":"java/execution/impl/src/com/intellij/execution/scratch/JavaScratchConfiguration.java","lineNumber":66,"sourceCode":"/**\n * @author Eugene Zhuravlev\n */\npublic final class JavaScratchConfiguration extends ApplicationConfiguration {\n  JavaScratchConfiguration(String name, @NotNull Project project, @NotNull ConfigurationFactory factory) {\n    super(name, project, factory);\n  }\n\n  @Override\n  public boolean isBuildProjectOnEmptyModuleList() {\n    return false;\n  }\n\n  @Override\n  public void checkConfiguration() throws RuntimeConfigurationException {\n    JavaParametersUtil.checkAlternativeJRE(this);\n    final String className = getMainClassName();\n    if (className == null || className.isEmpty()) {\n      throw new RuntimeConfigurationError(ExecutionBundle.message(\"no.main.class.specified.error.text\"));\n    }\n    if (getScratchFileUrl() == null) {\n      throw new RuntimeConfigurationError(JavaCompilerBundle.message(\"error.no.scratch.file.associated.with.configuration\"));\n    }\n    if (getScratchVirtualFile() == null) {\n      throw new RuntimeConfigurationError(JavaCompilerBundle.message(\"error.associated.scratch.file.not.found\"));\n    }\n    ProgramParametersUtil.checkWorkingDirectoryExist(this, getProject(), getConfigurationModule().getModule());\n    JavaRunConfigurationExtensionManager.checkConfigurationIsValid(this);\n  }\n\n  @Override\n  public RunProfileState getState(@NotNull Executor executor, @NotNull ExecutionEnvironment env) throws ExecutionException {\n    final JavaCommandLineState state = new JavaApplicationCommandLineState<>(this, env) {\n      @Override\n      protected JavaParameters createJavaParameters() throws ExecutionException {\n        final JavaParameters params = super.createJavaParameters();\n        // After params are fully configured, additionally ensure JAVA_ENABLE_PREVIEW_PROPERTY is set,","sourceCodeStart":48,"sourceCodeEnd":84,"githubUrl":"https://github.com/JetBrains/intellij-community/blob/be881553f2a76ac8b4ea53950d93f0de78295c19/java/execution/impl/src/com/intellij/execution/scratch/JavaScratchConfiguration.java#L48-L84","documentation":"JavaScratchConfiguration.checkConfiguration validates a Java scratch run configuration before execution. If the main class name derived from the scratch file is null or empty, it throws RuntimeConfigurationError with 'No main class specified', aborting the run at the configuration-check stage.","triggerScenarios":"Running a Java scratch file (or a JavaScratchConfiguration created via 'Run' in a scratch) where the scratch file contains no main method declaration the parser can find, so getMainClassName() returns null/empty.","commonSituations":"User writes a scratch class without 'public static void main' and hits Run; scratch file has a main-like method with wrong signature (e.g. no String[] arg); the scratch file's language level makes detection fail.","solutions":["Add a valid main method to the scratch file: public static void main(String[] args) { ... }","Make sure the class name in the scratch matches a top-level class (script-style scratch files without a class may also fail depending on version)","Re-run after saving the file so the main class is re-detected"],"exampleFix":"// before (scratch)\nclass Demo { static void run() {} }\n// after\nclass Demo { public static void main(String[] args) { run(); } }","handlingStrategy":"validation","validationCode":"// before running a scratch, check it declares a main method\nString main = JavaScratchConfigurationHelper.getMainClassName(scratchFile);\nif (main == null || main.isEmpty()) {\n  return notify(\"Scratch must contain 'public static void main(String[])'\");\n}","typeGuard":null,"tryCatchPattern":"try {\n  configuration.checkConfiguration();\n} catch (RuntimeConfigurationError e) {\n  // no main class: open the scratch and let the user add main()\n}","preventionTips":["Give every runnable scratch a canonical main(String[] args) signature","Save the scratch file before running so main-class detection re-runs","Keep the run action on files that are valid compilation units"],"tags":["scratch-file","run-configuration","main-class","validation"],"backgroundTag":null,"analyzedSha":"be881553f2a76ac8b4ea53950d93f0de78295c19","analyzedAt":"2026-08-14T14:13:06.425Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}