1

I built a simple program with javafx and have got to the part of deploying the app for use outside of intelliJ(community edition). I cant seem to figure out why the method isnt being invoked when i try launching the exe outside of the IDE.It shows two alert boxes, the first says Error invoking method, the second afterwards says Failed to launch JVM after I try and open the exe from explorer.

    package sample;
    import javafx.application.Application;
    import javafx.event.ActionEvent;
    import javafx.event.EventHandler;
    import javafx.geometry.Insets;
    import javafx.geometry.Pos;
    import javafx.scene.Scene;
    import javafx.scene.control.Label;
    import javafx.scene.control.PasswordField;
    import javafx.scene.control.TextField;
    import javafx.scene.layout.GridPane;
    import javafx.scene.layout.HBox;
    import javafx.scene.layout.StackPane;
    import javafx.scene.control.Button;
    import javafx.scene.paint.Color;
    import javafx.scene.text.Font;
    import javafx.scene.text.FontWeight;
    import javafx.scene.text.Text;
    import javafx.stage.Stage;

    public class Main extends Application {
        public static void main(String[] args) {
            launch(args);
        }

        @Override
        public void start(Stage primaryStage) throws Exception{
            primaryStage.setTitle("Welcome");
            primaryStage.setResizable(false);


         primaryStage.show();
            GridPane grid = new GridPane();
            grid.setAlignment(Pos.CENTER);
            grid.setHgap(10);
            grid.setVgap(10);
            grid.setPadding(new Insets(25, 25, 25, 25));
            //Adding text labels and text fields
            Text sceneTitle = new Text("Welcome");
            sceneTitle.setId("welcome-text");
            grid.add(sceneTitle, 0, 0,2, 1);
            TextField userTextField = new TextField();
            grid.add(userTextField, 1,1);
            Label userName = new Label("User Name: ");
            grid.add(userName, 0 ,1);
            Label pw = new Label("Password: ");
            grid.add(pw, 0,2);
            PasswordField pwBox = new PasswordField();
            grid.add(pwBox,1,2);
            //grid lines for debugging
            grid.setGridLinesVisible(false);
            //grid lines for debugging
            Button btn = new Button("Sign In");
            HBox hbBtn = new HBox(10);
            hbBtn.setAlignment(Pos.BOTTOM_RIGHT);
            hbBtn.getChildren().add(btn);
            grid.add(hbBtn, 1,4);
            final Text actionTarget = new Text();
            grid.add(actionTarget,1,6);
            btn.setOnAction(e -> {actionTarget.setText("Sign In button 
Pressed");});
        actionTarget.setId("actiontarget");
        Scene scene = new Scene(grid, 300, 275);
        primaryStage.setScene(scene);
        //Initialize sytlesheets variable
        scene.getStylesheets().add(Main.class.getResource("Login.css").toExternalForm());
        primaryStage.show();
    }
}

This is my controller class (lol)

    package sample;

    public class Controller {
    }

and finally... my fxml

<?import javafx.geometry.Insets?>
<?import javafx.scene.layout.GridPane?>

<?import javafx.scene.control.Button?>
<?import javafx.scene.control.Label?>
<GridPane fx:controller="sample.Controller"
          xmlns:fx="http://javafx.com/fxml" alignment="center" hgap="10" vgap="10">
</GridPane>

the last thing i have to help out is this here but im not sure how to read it to get to the base of the issue...

C:\Users\Joop\IdeaProjects\Hello\out\artifacts\JavaFXApp\bundles>java -jar "JavaFXApp.jar"
Exception in Application start method
java.lang.reflect.InvocationTargetException
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
        at java.lang.reflect.Method.invoke(Unknown Source)
        at com.sun.javafx.application.LauncherImpl.launchApplicationWithArgs(LauncherImpl.java:389)
        at com.sun.javafx.application.LauncherImpl.launchApplication(LauncherImpl.java:328)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
        at java.lang.reflect.Method.invoke(Unknown Source)
        at sun.launcher.LauncherHelper$FXHelper.main(Unknown Source)
Caused by: java.lang.RuntimeException: Exception in Application start method
        at com.sun.javafx.application.LauncherImpl.launchApplication1(LauncherImpl.java:917)
        at com.sun.javafx.application.LauncherImpl.lambda$launchApplication$154(LauncherImpl.java:182)
        at java.lang.Thread.run(Unknown Source)
Caused by: java.lang.NullPointerException
        at sample.Main.start(Main.java:64)
        at com.sun.javafx.application.LauncherImpl.lambda$launchApplication1$161(LauncherImpl.java:863)
        at com.sun.javafx.application.PlatformImpl.lambda$runAndWait$174(PlatformImpl.java:326)
        at com.sun.javafx.application.PlatformImpl.lambda$null$172(PlatformImpl.java:295)
        at java.security.AccessController.doPrivileged(Native Method)
        at com.sun.javafx.application.PlatformImpl.lambda$runLater$173(PlatformImpl.java:294)
        at com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:95)
        at com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
        at com.sun.glass.ui.win.WinApplication.lambda$null$147(WinApplication.java:177)
        ... 1 more
Exception running application sample.Main
Michael Berry
  • 70,193
  • 21
  • 157
  • 216
Joop
  • 11
  • 2
  • 1
    You'll probably benefit from reading https://stackoverflow.com/q/3988788 and https://stackoverflow.com/q/218384 – James_D May 02 '18 at 15:37
  • +1 for a "basic", but well structured and presented question, with full stack trace and relevant code. Welcome to SO! – Michael Berry May 03 '18 at 07:47

1 Answers1

2

im not sure how to read it to get to the base of the issue...

The key part is this:

Caused by: java.lang.NullPointerException
    at sample.Main.start(Main.java:64)

That shows you that Main.java, line 64 threw a NullPointerException. So the exception is thrown because of the following line:

scene.getStylesheets().add(Main.class.getResource("Login.css").toExternalForm());

Specifically, it's most likely that Main.class.getResource("Login.css") is returning null. This will be because it can't find the Login.css, almost certainly because you haven't included it in your build (hence why you can't run it successfully outside the IDE.)

Michael Berry
  • 70,193
  • 21
  • 157
  • 216
  • 1
    Thank you. I gathered that was the exact issue when I tried to run it. Thank you for everything. Even with such a "basic' issue, you've definitely helped me on my journey with this insight. – Joop May 03 '18 at 17:21