JetBrains/intellij-community · error · IllegalArgumentException

Main method is not found

Error message

Main method is not found

What it means

AppMainV2 is IntelliJ's Java application launcher (the class actually started for 'Application' run configurations using the v2 launcher). It resolves the main class from the command line, first tries findMethodToRun (which covers both classic static void main(String[]) and Java 25+ instance-main forms), then falls back to Class.getMethod("main", String[].class). If neither exists, it makes a last attempt to start the class as a JavaFX Application; when that also fails it throws IllegalArgumentException('Main method is not found'). In short: the class on the run configuration's command line has no runnable entry point and is not a JavaFX Application.

Source

Thrown at java/java-runtime/src/com/intellij/rt/execution/application/AppMainV2.java:76

    }

    String[] params = args;
    String mainClass = System.getProperty(LAUNCHER_MAIN_CLASS);
    if (mainClass == null) {
      mainClass = args[0];
      System.setProperty(LAUNCHER_MAIN_CLASS, mainClass);
      params = Arrays.copyOfRange(args, 1, args.length);
    }

    Class<?> appClass = Class.forName(mainClass);
    Method m = findMethodToRun(appClass);
    if (m == null) {
      try {
        // left for compatibility reasons and as a fallback
        m = appClass.getMethod("main", String[].class);
      } catch (NoSuchMethodException e) {
        if (!startJavaFXApplication(params, appClass)) {
          throw new IllegalArgumentException("Main method is not found");
        }
        return;
      }
    }

    if (!void.class.isAssignableFrom(m.getReturnType())) {
      System.err.println("main method must return a value of type void");
      return;
    }

    try {
      m.setAccessible(true);
      int parameterCount = m.getParameterTypes().length;
      Object objInstance = null;
      if (!Modifier.isStatic(m.getModifiers())) {
        Constructor<?> declaredConstructor;
        try {
          declaredConstructor = appClass.getDeclaredConstructor();

View on GitHub (pinned to be881553f2)

Solutions

  1. Open the Run/Debug Configuration and verify the 'Main class' field names the exact class that declares public static void main(String[] args) (use the full FQN, e.g. com.example.MyApp, and Outer$Inner syntax for nested classes).
  2. Add a main method to the target class: public static void main(String[] args) { ... } — or for JavaFX, make the class extend javafx.application.Application and implement start(Stage).
  3. If the class is JavaFX, ensure the JavaFX SDK/modules (javafx.graphics, javafx.controls) are on the module path or classpath so startJavaFXApplication can instantiate and launch it.
  4. After a rename/move, let the IDE update the run configuration (refactor with Shift+F6 rather than editing names by hand), or delete and recreate the configuration.
  5. If you rely on an inherited main from a superclass, declare a delegating main in the concrete class you launch.

Example fix

// before: no entry point -> 'Main method is not found'
public class Greeter {
  void run() { System.out.println("hi"); }
}

// after: runnable entry point
public class Greeter {
  public static void main(String[] args) {
    new Greeter().run();
  }
  void run() { System.out.println("hi"); }
}
Defensive patterns

Strategy: validation

Validate before calling

// Before launching, verify the entry point exists:
Class<?> c = Class.forName(mainClassName);
boolean runnable = false;
for (Method m : c.getMethods()) {
  if ("main".equals(m.getName())
      && Modifier.isStatic(m.getModifiers())
      && m.getParameterCount() == 1
      && m.getParameterTypes()[0] == String[].class
      && m.getReturnType() == void.class) {
    runnable = true; break;
  }
}
if (!runnable && !javafx.application.Application.class.isAssignableFrom(c)) {
  throw new IllegalStateException(mainClassName + " has no main method and is not a JavaFX Application");
}

Prevention

When it happens

Trigger: Running a configuration whose main class (a) declares no static or instance main method with a compatible signature (e.g. main takes int[] instead of String[], or is private in a version where findMethodToRun does not widen access), (b) is a nested/inner class referenced without the Outer$Inner binary name, or (c) extends neither javafx.application.Application while expecting JavaFX launch to succeed.

Common situations: Run configuration points at a class without a main method (e.g. a utility or data class picked by accident in the 'Main class' field); typo or stale FQN after refactoring/renaming the class; Kotlin/Scala classes whose main has a different shape than expected by this launcher path; JavaFX projects where javafx.application.Application is not on the classpath/module path so startJavaFXApplication fails; running a class whose only main is in a superclass but the launcher cannot inherit it.

Related errors


AI-assisted analysis of JetBrains/intellij-community@be881553f2 (2026-08-14). Data as JSON: /api/errors/8e69232570eeb9fe. Report an issue: GitHub.