java - 运行 JavaFX 时应用程序启动方法中的异常
问题描述
启动 javaFX 应用程序时出现 java.lang.reflect.InvocationTargetException 错误。有什么帮助吗?我相信这与 .add(btns...) 有关,但堆栈跟踪显示我的代码中没有任何行导致问题。
@Override
public void start(Stage primaryStage) {
GridPane root = new GridPane();
for (int i = 0; i < game.getRows(); i++) {
for (int j = 0; j < game.getColumns(); j++) {
btns[i][j] = new Button(" ");
root.add(btns[i][j], j, i, 1, 1);
}
}
/*btn.setOnAction(new EventHandler<ActionEvent>() {
@Override
public void handle(ActionEvent event) {
}
});*/
Button newGame = new Button("New Game");
Button quit = new Button("Quit");
root.add(newGame, game.getColumns(), 0);
root.add(quit, game.getColumns(), 1);
Scene scene = new Scene(root);
primaryStage.setTitle("Minesweeper");
primaryStage.setScene(scene);
primaryStage.show();
}
这是完整的堆栈跟踪
Exception in Application start method
java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at com.sun.javafx.application.LauncherImpl.launchApplicationWithArgs(LauncherImpl.java:389)
at com.sun.javafx.application.LauncherImpl.launchApplication(LauncherImpl.java:328)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at sun.launcher.LauncherHelper$FXHelper.main(LauncherHelper.java:767)
Caused by: java.lang.RuntimeException: Exception in Application start method
at com.sun.javafx.application.LauncherImpl.launchApplication1(LauncherImpl.java:917)
at com.sun.javafx.application.LauncherImpl.lambda$launchApplication$1(LauncherImpl.java:182)
at java.lang.Thread.run(Thread.java:748)
Caused by: java.lang.IllegalArgumentException: Children: duplicate children added: parent = Grid hgap=0.0, vgap=0.0, alignment=TOP_LEFT
at javafx.scene.Parent$2.onProposedChange(Parent.java:454)
at com.sun.javafx.collections.VetoableListDecorator.add(VetoableListDecorator.java:206)
at javafx.scene.layout.GridPane.add(GridPane.java:980)
at part3.MinesweeperGUI.start(MinesweeperGUI.java:48)
at com.sun.javafx.application.LauncherImpl.lambda$launchApplication1$8(LauncherImpl.java:863)
at com.sun.javafx.application.PlatformImpl.lambda$runAndWait$7(PlatformImpl.java:326)
at com.sun.javafx.application.PlatformImpl.lambda$null$5(PlatformImpl.java:295)
at java.security.AccessController.doPrivileged(Native Method)
at com.sun.javafx.application.PlatformImpl.lambda$runLater$6(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$4(WinApplication.java:186)
... 1 more
Exception running application part3.MinesweeperGUI
Java Result: 1
解决方案
推荐阅读
- javascript - 在离子/角度中将字符串日期“d/m/y”格式化为“dd/mm/yyyy”
- python - 使用 gspread 创建的电子表格正在与我组织中的所有用户共享
- python-3.x - 将数据框中的所有项转换为浮点数
- python - 如何保存通过camera.capture_continuous(格式rgb)读取的图像并将其保存到文件中
- reactjs - 用于 React 挂钩常量的 useMemo 与 useState
- javascript - 过渡问题 CSS 和 JS
- swift - 如何在 swift setMethodCallHandler 中使用传递的参数 - self?.methodName(result: result)
- qmail - 一个帐户正在迁移。如何停止该单个域的本地传递并使用不同的邮件服务器?
- php - 如何将 PDO 转换为 MYSQLi
- java - 如何解决spring-boot的冲突实体