代码之家  ›  专栏  ›  技术社区  ›  Clyde Frog

无法构造应用程序实例[重复]

  •  -1
  • Clyde Frog  · 技术社区  · 6 年前

    我试图在公共类中启动在另一个类中定义的应用程序,从而获得“无法构造应用程序实例”--异常。下面的示例非常简单。我错过了什么?——线索会很有帮助的。

    这个问题与这个问题不同

    Unable to construct javafx.application.Application instance

    因为我想在单独的类中定义应用程序及其启动。

    import javafx.application.Application;
    import javafx.scene.Scene;
    import javafx.scene.control.Button;
    import javafx.stage.Stage;
    
    public class Main {
        public static void main(String[] args) {
            Application.launch(OKButton.class, args);
        }
    }
    
    class OKButton extends Application {
        @Override
        public void start(Stage stage) {
            Button btn = new Button("OK");
            Scene scene = new Scene(btn, 200, 250);
            stage.setScene(scene);
            stage.show();
        }
    }
    
    1 回复  |  直到 6 年前
        1
  •  1
  •   Halko Karr-Sajtarevic    6 年前

    OKButton

    public class Main {
        public static void main(String[] args) {
            Application.launch(OKButton.class, args);
        }
    
        public static class OKButton extends Application {
    
            @Override
            public void start(Stage stage) {
                Button btn = new Button("OK");
                Scene scene = new Scene(btn, 200, 250);
                stage.setScene(scene);
                stage.show();
            }
        }
    }