Trying to call a JavaFX application from Java… NoSuchMethodException

前端 未结 1 526
陌清茗
陌清茗 2020-12-01 22:23

I have a main class which should call a JavaFX application (SimpleSun) to get Information from the user. Currently I create an Object of the JavaFX class and start it, but t

相关标签:
1条回答
  • 2020-12-01 22:52

    You must provide a constructor with no arguments when you extend application. So you could do something like:

    public class SimpleSun extends Application {
    
        private Stage primaryStage;
        Configuration configuration;
    
        public SimpleSun() {
            this.configuration = Main.getConfig();
        }
        //...
    

    and in your Main class:

    public static Configuration getConfig() { return new ConfigurationFromFile(); }
    

    Alternatively you can pass String parameters to the class with launch(args) and get them back in the SimpleSun class with getParameters().

    0 讨论(0)
提交回复
热议问题