0

I just designed a simple javaFx app. While running it solo works, but when I try to separated and create an instance of it all I get :

at com.sun.javafx.application.PlatformImpl.lambda$null$173(PlatformImpl.java:295)
at java.security.AccessController.doPrivileged(Native Method)
at com.sun.javafx.application.PlatformImpl.lambda$runLater$174(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$148(WinApplication.java:191)
... 1 more

my code

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

public class Demo 
{
    public static void main(String[] args) 
    {

        Demos dm = new Demos();

    }
}

class Demos extends Application {
    private String args;
    private Stage stage;

    public Demos()
    {
        main(args);
        start(stage);

    }

    public void main(String args) 
    {
        this.args=args;
        launch(this.args);

    }

    @Override
    public void start(Stage stage)
    {
        this.stage=stage;
        this.stage.setTitle("Simple JavaFX Application");
        this.stage.setResizable(false);
        this.stage.show();
    }

}
fabian
  • 80,457
  • 12
  • 86
  • 114
Muzy
  • 15
  • 1
  • 7

1 Answers1

0

Application.launch requires the Application class to be lauched to be public. This is not the case for your Demos class.

Additional Notes

private String args;
private Stage stage;

public Demos()
{
    main(args);
    ...
}

public void main(String args) 
{
    this.args=args;
    ...
}

Just assigns the initial value of args to itself, which will always result in args remaining null.


Application.launch is a static method creating the Application instance itself. Calling this form from a instance makes little sense.

If you want to launch a specific Application, pass the Application class to Application.launch:

public static void main(String[] args) {
    Application.launch(Demos.class);
}
public Demos extends Application {
    private Stage stage;

    public Demos(){
    }

    @Override
    public void start(Stage stage) {
        this.stage=stage;
        this.stage.setTitle("Simple JavaFX Application");
        this.stage.setResizable(false);
        this.stage.show();
    }

}
fabian
  • 80,457
  • 12
  • 86
  • 114