{"record":{"id":"a6918d9d7006a047","repo":"JetBrains/intellij-community","slug":"no-main-class-defined","errorCode":null,"errorMessage":"No main class defined","messagePattern":"No main class defined","errorType":"exception","errorClass":"CantRunException","httpStatus":null,"severity":"error","filePath":"java/execution/impl/src/com/intellij/execution/application/ApplicationCommandLineState.java","lineNumber":67,"sourceCode":"      .expireWith(expireReadsWith)\n      .executeSynchronously();\n\n    params.setMainClass(mainClass);\n    try {\n      JavaParametersUtil.configureConfiguration(params, configuration);\n    }\n    catch (ProgramParametersConfigurator.ParametersConfiguratorException e) {\n      throw new ExecutionException(e);\n    }\n\n    final JavaRunConfigurationModule module = configuration.getConfigurationModule();\n    try {\n      ReadAction.nonBlocking(() -> {\n        final String jreHome = getTargetEnvironmentRequest() == null && configuration.isAlternativeJrePathEnabled() ? configuration.getAlternativeJrePath() : null;\n        if (module.getModule() != null) {\n          DumbService.getInstance(module.getProject()).runWithAlternativeResolveEnabled(() -> {\n            if (mainClass == null) {\n              throw new CantRunException(ExecutionBundle.message(\"no.main.class.defined.error.message\"));\n            }\n            int classPathType = JavaParametersUtil.getClasspathType(module, mainClass, false,\n                                                                    isProvidedScopeIncluded());\n            // todo effects must be applied in non-cancellable section\n            JavaParametersUtil.configureModule(module, params, classPathType, jreHome);\n          });\n        }\n        else {\n          // todo effects must be applied in non-cancellable section\n          JavaParametersUtil.configureProject(module.getProject(), params, JavaParameters.JDK_AND_CLASSES_AND_TESTS, jreHome);\n        }\n        return null;\n      })\n        .expireWith(expireReadsWith)\n        .executeSynchronously();\n    }\n    catch (Exception e) {\n      ExecutionException executionException = ExceptionUtil.findCause(e, ExecutionException.class);","sourceCodeStart":49,"sourceCodeEnd":85,"githubUrl":"https://github.com/JetBrains/intellij-community/blob/be881553f2a76ac8b4ea53950d93f0de78295c19/java/execution/impl/src/com/intellij/execution/application/ApplicationCommandLineState.java#L49-L85","documentation":"ApplicationCommandLineState.createJavaParameters runs a non-blocking read action that configures the classpath; inside it, if mainClass is null it throws CantRunException('No main class defined'). This is the standard guard for a Java Application run configuration whose main class field is empty or unresolved.","triggerScenarios":"Application run configuration with an empty 'Main class' field, or a main class name that resolved to null during state creation (e.g. configuration created programmatically or from a launcher template without setting the main class).","commonSituations":"Newly created 'Application' configuration where the user never picked a main class; shared/checked-in .run XML referencing a class that no longer exists; templates in plugins creating configurations without a main class; running a scratch/main file before it has a valid main method.","solutions":["Edit the run configuration and set 'Main class' to a class containing 'public static void main(String[])'","If the class exists but is not detected, make sure the file is a valid class with a proper main signature and the module is compiled","For checked-in configurations, update the main class FQN after refactoring/moving the class","If the main class uses preview features or is in a non-compiling module, fix compilation first so the class resolves"],"exampleFix":"// before: RunConfiguration mainClass = null\n// after: runConfig.setMainClassName(\"com.example.MyApp\");","handlingStrategy":"validation","validationCode":"// before starting, ensure the main class is set and resolvable\nString main = configuration.getMainClassName();\nif (main == null || main.isBlank() || JavaPsiFacade.getInstance(project).findClass(main, GlobalSearchScope.allScope(project)) == null) {\n  return error(\"Main class is missing or does not resolve\");\n}","typeGuard":null,"tryCatchPattern":"try {\n  super.createJavaParameters();\n} catch (CantRunException e) {\n  // surface 'No main class defined' to the user with a link to edit the configuration\n  showEditConfigurationDialog(e);\n}","preventionTips":["Always pick the main class via the class chooser, not free text","After moving/renaming main classes, let the IDE update run configurations (refactor with IDE, not shell)","Validate shared .run XML files after refactors"],"tags":["run-configuration","application","main-class","execution"],"backgroundTag":null,"analyzedSha":"be881553f2a76ac8b4ea53950d93f0de78295c19","analyzedAt":"2026-08-14T14:13:06.425Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}