这种情况一般是jdk11以上会出现,最简单直接的解决办法就是新建一个启动类来引导你的application类的运行。
public class Test extends Application {
@Override
public void start(Stage primaryStage) throws Exception {
Button choose = new Button("颜色选择器");
VBox box = new VBox(choose);
box.setPadding(new Insets(20));
box.setSpacing(20);
Scene scene = new Scene(box);
primaryStage.setScene(scene);
primaryStage.setWidth(500);
primaryStage.setHeight(500);
primaryStage.setX(940.0);
primaryStage.setY(400.0);
primaryStage.setTitle("你好(500*500)");
primaryStage.show();
choose.setOnAction(event->{
Newstage newstage = new Newstage();
try {
newstage.start(new Stage());
} catch (Exception e) {
throw new RuntimeException(e);
}
});
}
public static void main(String[] args) {
launch(args);
}
}
在java8里这段代码可以直接运行,但是11以上会报错,此时新建一个启动类:
public class ToStart {
public static void main(String[] args) {
Test.main(args);
}
}
运行这个启动类就行了。