Eclipse 如何创建扩展应用程序的类的实例

Eclipse 如何创建扩展应用程序的类的实例,eclipse,javafx,Eclipse,Javafx,我刚刚设计了一个简单的javaFx应用程序。虽然单独运行它是可行的,但当我尝试分离并创建它的实例时,我得到的是: 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

我刚刚设计了一个简单的javaFx应用程序。虽然单独运行它是可行的,但当我尝试分离并创建它的实例时,我得到的是:

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
我的代码

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();
    }

}

Application.launch
要求要启动的
Application
类为
public
。对于您的
演示
类,情况并非如此

附加注释

private String args;
private Stage stage;

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

public void main(String args) 
{
    this.args=args;
    ...
}
只需将
args
的初始值分配给自身,这将始终导致
args
剩余
null



Application.launch
是一种创建
应用程序
实例本身的
静态
方法。从实例调用此表单没有什么意义

如果要启动特定的
应用程序
,请将
应用程序
类传递给
应用程序。启动

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

您不能自己构造FX应用程序。您使用它的
launch
方法。我想这个问题已经在这里解决了:
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();
    }

}