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

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

    Details

    • Type: Bug
    • Status: Open
    • Priority: P4
    • Resolution: Unresolved
    • Affects Version/s: 8, 9, openjfx11, openjfx13
    • Fix Version/s: openjfx14
    • Component/s: javafx
    • Labels:

      Description

      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

        Attachments

          Activity

            People

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

              Dates

              • Created:
                Updated: