Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8230119

NullPointerException if Application subclass has non-static main(String[]) method

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Unresolved
    • Icon: P4 P4
    • tbd
    • jfx11, jfx13, 8, 9
    • javafx

      To reproduce, run the following program:

      import javafx.application.Application;
      import javafx.application.Platform;
      import javafx.stage.Stage;

      public class App extends Application {

          @Override
          public void start(Stage primaryStage) {
              System.out.println("Application launched successfully");
              Platform.exit();
          }

          // non-static
          public void main(String[] args) {
              System.out.println("main method called");
              Application.launch(args);
          }

      }

      The following exception is thrown:

      $ java App
      Exception in thread "main" java.lang.reflect.InvocationTargetException
              at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
              at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
              at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
              at java.base/java.lang.reflect.Method.invoke(Method.java:565)
              at java.base/sun.launcher.LauncherHelper$FXHelper.main(LauncherHelper.java:1051)
      Caused by: java.lang.NullPointerException
              at java.base/java.lang.reflect.Method.invoke(Method.java:558)
              at javafx.graphics/com.sun.javafx.application.LauncherImpl.launchApplicationWithArgs(LauncherImpl.java:464)
              at javafx.graphics/com.sun.javafx.application.LauncherImpl.launchApplication(LauncherImpl.java:363)
              ... 5 more

            kcr Kevin Rushforth
            kcr Kevin Rushforth
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated: