你能否帮我解决这个错误。我一直试图弄清楚这里的问题在哪里。 也许是我没见过的东西。这是一个非常简单的程序。我没有太多java经验。
这是代码。
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);
}
}
这是错误。
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
提前感谢你们的任何帮助
答案 0 :(得分:1)
问题在于:
leftpane.add(lblPhoneNumber, 0, 6);
leftpane.add(tfPhoneNumber, 1, 6);
您已经添加了lblPhoneNumber,此处:
leftpane.add(lblPhoneNumber, 0, 3);
leftpane.add(tfPhoneNumber, 1, 3);
异常Caused by: java.lang.IllegalArgumentException: Children: duplicate children added
只是试图告诉您,您无法在网格的另一个位置再次添加同一个对象。