0

Can you please help me with this error. I have been trying to figure out where is the issue here. Maybe is something that I haven't seen. This is a program that should be very simple. I don't have much experience in java.

This is the code.

public class StudentInfo extends Application {
@Override // Override the start method in the Application class
  public void start(Stage primaryStage) {
    // Create a pane and set its properties

    BorderPane mainpane = new BorderPane();
    GridPane leftpane = new GridPane();
    leftpane.setAlignment(Pos.CENTER);
    leftpane.setPadding(new Insets(11.5, 12.5, 13.5, 14.5));
    leftpane.setHgap(5);
    leftpane.setVgap(5.5);
    //FlowPane pane = new FlowPane(Orientation.VERTICAL);
    //pane.setPadding(new Insets(11, 12, 13, 14));
    //pane.setHgap(5);
    //pane.setVgap(5);

    //String[] computerCourses = {"Select a course","Python", "C#", "Dephi","Java","XML"};
    //String[] businessCourses = {"Select a course","Finance","Marketing","Investment Analysis","Business Communications"};

    // Place nodes in the pane

    Label lblName = new Label("Name:");
    Label lblAddress = new Label("Adress:");
    Label lblProvince = new Label("Province");
    Label lblCity = new Label("City:");
    Label lblPostalCode = new Label("Postal Code:");
    Label lblPhoneNumber = new Label("Phone number:");
    Label lblEmail = new Label("Email:");

    //VBox vBox = new VBox(5);
    //vBox.setPadding(new Insets(15, 5, 5, 5));
    //vBox.getChildren().add(lblName);
    //vBox.getChildren().add(lblAddress);
    //vBox.getChildren().add(lblProvince);
    //vBox.getChildren().add(lblCity);
    //vBox.getChildren().add(lblPostalCode);
    //vBox.getChildren().add(lblPhoneNumber);
    //vBox.getChildren().add(lblEmail);

    //mainpane.setLeft(vBox);
    TextField tfName = new TextField();
    TextField tfAddress = new TextField();
    TextField tfProvince = new TextField();
    TextField tfCity = new TextField();
    TextField tfPostalCode = new TextField();
    TextField tfPhoneNumber = new TextField();
    TextField tfEmail = new TextField();

    leftpane.add(lblName, 0, 0);
    leftpane.add(tfName, 1, 0);
    leftpane.add(lblAddress, 0, 1); 
    leftpane.add(tfAddress, 1, 1);
    leftpane.add(lblProvince, 0, 2);
    leftpane.add(tfProvince, 1, 2);
    leftpane.add(lblPhoneNumber, 0, 3);
    leftpane.add(tfPhoneNumber, 1, 3);
    leftpane.add(lblCity, 0, 4);
    leftpane.add(tfCity, 1, 4);
    leftpane.add(lblPostalCode, 0, 5);
    leftpane.add(tfPostalCode, 1, 5);
    leftpane.add(lblPhoneNumber, 0, 6);
    leftpane.add(tfPhoneNumber, 1, 6);
    leftpane.add(lblEmail, 0, 7);
    leftpane.add(tfEmail, 1, 7);

    mainpane.setLeft(leftpane);
    //Button btDisplay = new Button("Display");

    //CheckBox chkStudentCouncil = new CheckBox("Bold");
    //CheckBox chkVolunteerWork = new CheckBox("Bold");

    //RadioButton rbComputerScience = new RadioButton("Computer Science");
    //RadioButton rbBusiness = new RadioButton("Business"); 
    //ComboBox<String> cbCourses = new ComboBox<>();
    //ListView<String> lvCourses = new ListView<>(); 
    //pane.getChildren().addAll(lblName, lblAddress, lblProvince, lblCity, lblPostalCode, lblPhoneNumber, lblEmail); 

    // Create a scene and place it in the stage
    Scene scene = new Scene(mainpane, 1000, 300);
    primaryStage.setTitle("Student Information"); // Set the stage title
    primaryStage.setScene(scene); // Place the scene in the stage
    primaryStage.show(); // Display the stage
  }

  /**
   * The main method is only needed for the IDE with limited
   * JavaFX support. Not needed for running from the command line.
   */
  public static void main(String[] args) {
    launch(args);
  }

}

This is the error.

Exception in Application start method
java.lang.reflect.InvocationTargetException

    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)

    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)

    at java.lang.reflect.Method.invoke(Unknown Source)

    at com.sun.javafx.application.LauncherImpl.launchApplicationWithArgs(Unknown Source)

    at com.sun.javafx.application.LauncherImpl.launchApplication(Unknown Source)

    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)

    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)

    at java.lang.reflect.Method.invoke(Unknown Source)

    at sun.launcher.LauncherHelper$FXHelper.main(Unknown Source)

Caused by: java.lang.RuntimeException: Exception in Application start method

    at com.sun.javafx.application.LauncherImpl.launchApplication1(Unknown Source)

    at com.sun.javafx.application.LauncherImpl.lambda$launchApplication$147(Unknown Source)

    at com.sun.javafx.application.LauncherImpl$$Lambda$48/128893786.run(Unknown Source)

    at java.lang.Thread.run(Unknown Source)

Caused by: java.lang.IllegalArgumentException: Children: duplicate children added: parent = Grid hgap=5.0, vgap=5.5, alignment=CENTER

    at javafx.scene.Parent$2.onProposedChange(Unknown Source)

    at com.sun.javafx.collections.VetoableListDecorator.add(Unknown Source)

    at javafx.scene.layout.GridPane.add(Unknown Source)

    at StudentInfo.start(StudentInfo.java:71)

    at com.sun.javafx.application.LauncherImpl.lambda$launchApplication1$153(Unknown Source)

    at com.sun.javafx.application.LauncherImpl$$Lambda$51/488112689.run(Unknown Source)

    at com.sun.javafx.application.PlatformImpl.lambda$runAndWait$166(Unknown Source)

    at com.sun.javafx.application.PlatformImpl$$Lambda$45/1051754451.run(Unknown Source)

    at com.sun.javafx.application.PlatformImpl.lambda$null$164(Unknown Source)

    at com.sun.javafx.application.PlatformImpl$$Lambda$47/1184297595.run(Unknown Source)

    at java.security.AccessController.doPrivileged(Native Method)

    at com.sun.javafx.application.PlatformImpl.lambda$runLater$165(Unknown Source)

    at com.sun.javafx.application.PlatformImpl$$Lambda$46/1775282465.run(Unknown Source)

    at com.sun.glass.ui.InvokeLaterDispatcher$Future.run(Unknown Source)

    at com.sun.glass.ui.win.WinApplication._runLoop(Native Method)

    at com.sun.glass.ui.win.WinApplication.lambda$null$141(Unknown Source)

    at com.sun.glass.ui.win.WinApplication$$Lambda$37/1109371569.run(Unknown Source)
        ... 1 more
    Exception running application StudentInfo

Thanks in advance for any help that you guys

0

1 Answer 1

1

The problem is here:

leftpane.add(lblPhoneNumber, 0, 6);
leftpane.add(tfPhoneNumber, 1, 6);

You've already added lblPhoneNumber, here:

leftpane.add(lblPhoneNumber, 0, 3);
leftpane.add(tfPhoneNumber, 1, 3);

The exception Caused by: java.lang.IllegalArgumentException: Children: duplicate children added is simply trying to tell you that you can't added the same object again in another location of the grid.

Sign up to request clarification or add additional context in comments.

1 Comment

Thank you so much. It was a simple copy and paste mistake. I guess I couldn't see it because I was feeling too tired.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.