0

I get a java.lang.reflect.InvocationTargetException error when starting up my javaFX application. Any help? I believe it is something to do with the .add(btns...), but the stack trace shows that none of the lines in my code are causing the problem.

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

Here is the full stack trace

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
P555
  • 11
  • 2
  • Use the [stack trace](https://stackoverflow.com/questions/3988788/what-is-a-stack-trace-and-how-can-i-use-it-to-debug-my-application-errors) to identify the problem. If you really can't figure out what's happening, post the stack trace (formatted as code) in the question, and identify the exact line in the code that is responsible. – James_D Apr 17 '20 at 14:43
  • @James_D provided my stack trace, still can't seem to find problem – P555 Apr 17 '20 at 14:49
  • I don't see how the code you posted can cause that exception. Are you sure you saved the file, and that this is actually the code you're running? Which is line 48? – James_D Apr 17 '20 at 14:53
  • Line 48 is the commented out btn.setonaction, the thing is this same code was working a couple days ago, I've tried copying into the a new FX file, but no luck... – P555 Apr 17 '20 at 16:57
  • So, obviously, you cannot be running the same version of the code that you are looking at (a commented-out line cannot possibly throw any kind of exception). Make sure all your files are saved, clean the project and run it again. – James_D Apr 17 '20 at 16:58

0 Answers0