2014-10-19 67 views
0

你能幫我解決這個錯誤嗎?我一直在試圖弄清楚問題在哪裏。也許是我沒有看到的東西。這是一個應該非常簡單的程序。我沒有太多的Java經驗。javafx中的java.lang.reflect.InvocationTargetException中的異常

這是代碼。

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 

在此先感謝您的幫助,你們

回答

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只是試圖告訴你,你不能再次在另一個位置添加相同的對象電網。

+0

非常感謝。這是一個簡單的複製和粘貼錯誤。我想我看不到它,因爲我感覺太累了。 – Vicente 2014-10-20 02:06:35

相關問題