0

how do I prevent this crash? It only happens when I click the comboboxes, and I have no idea why

Method that when a button is clicked, the window loads:

@FXML
public Stage displayAddNewPerson() {

    FXMLLoader fxmlLoader = new FXMLLoader(getClass().getResource("CreateNewStudent.fxml"));
    Parent root;
    Stage addNewPersonStage = new Stage();
    try {
        root = fxmlLoader.load();

        addNewPersonStage.initModality(Modality.APPLICATION_MODAL);
        addNewPersonStage.setOpacity(1);
        addNewPersonStage.setTitle("My New Stage Title");
        addNewPersonStage.setScene(new Scene(root, 500, 300));
        AddNewPersonToFile controller = fxmlLoader.<AddNewPersonToFile>getController();
        controller.initData();
        addNewPersonStage.showAndWait();
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

    return addNewPersonStage;

}

Controller class of the newly opened window:

public class AddNewPersonToFile extends AnchorPane{
    @FXML
    final ObservableList<String> stateList =FXCollections.observableArrayList(
            "AL", "AK", "AZ", "AR", "CA", "CO", "CT", "DE", "FL", "GA", "HI", "ID", "IL", "IN", 
            "IA","KS", "KY", "LA", "ME", "MD", "MA", "MI", "MN", "MS", "MO", "MT", "NE", "NV", 
            "NH", "NJ", "NM", "NY", "NC", "ND", "OH", "OK", "OR", "PA", "RI", "SC", "SD", "TN", 
            "TX","UT", "VT", "VA", "WA", "WV", "WI", "WY");
    @FXML
    private TextField enterLastName;
    @FXML
    private TextField enterFirstName;
    @FXML
    private TextField enterEmail;
    @FXML
    private TextField enterMoneyOwed;
    @FXML
    private TextField enterSchoolName;
    @FXML
    private ComboBox<String> enterState; 
    @FXML
    private ComboBox<Integer> enterYearJoined;
    @FXML
    private CheckBox enterIsHeActive;
    @FXML
    private Button enterStudentInfo;
    void initialize(){};
    public void initData() {

        int year = Calendar.getInstance().get(Calendar.YEAR);
        ObservableList<Integer> yearRange = FXCollections.observableArrayList((year - 4), (year - 3), (year - 2), (year - 1), (year), (year + 1), (year + 2), (year + 3), (year + 4));
        enterIsHeActive.setIndeterminate(false);
        System.setProperty("glass.accessible.force", "false");
        enterState.setVisibleRowCount(4);
        enterState.setItems(stateList);
        enterYearJoined.setItems(yearRange);
        enterYearJoined.setVisibleRowCount(4);


    }

FXML of the new window:

<AnchorPane xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1" fx:controller="fbla.rahulshah.database.view.AddNewPersonToFile">
   <children>
      <AnchorPane layoutY="1.0" maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="300.0" prefWidth="500.0">
         <children>
            <Label layoutX="6.0" layoutY="6.0" text="Create New Student">
               <font>
                  <Font size="32.0" />
               </font>
            </Label>
            <TextField fx:id="enterLastName" layoutX="14.0" layoutY="70.0" prefHeight="25.0" prefWidth="150.0" promptText="Last Name">
               <font>
                  <Font size="9.0" />
               </font>
            </TextField>
            <TextField fx:id="enterFirstName" layoutX="170.0" layoutY="70.0" prefHeight="25.0" prefWidth="141.0" promptText="First Name">
               <font>
                  <Font size="9.0" />
               </font>
            </TextField>
            <TextField fx:id="enterEmail" layoutX="316.0" layoutY="70.0" prefHeight="25.0" prefWidth="176.0" promptText="Email">
               <font>
                  <Font size="9.0" />
               </font>
            </TextField>
            <Label layoutX="14.0" layoutY="53.0" text="Personal Info" />
            <Label layoutX="19.0" layoutY="147.0" text="School Info" />
            <TextField fx:id="enterSchoolName" layoutX="14.0" layoutY="166.0" prefHeight="25.0" prefWidth="150.0" promptText="School's Full Name">
               <font>
                  <Font size="9.0" />
               </font>
            </TextField>
            <CheckBox fx:id="enterIsHeActive" layoutX="16.0" layoutY="209.0" mnemonicParsing="false" text="Check if Active member" />
            <Button layoutX="416.0" layoutY="261.0" mnemonicParsing="false" text="Enter Info" />
            <TextField fx:id="enterMoneyOwed" layoutX="191.0" layoutY="109.0" prefHeight="25.0" prefWidth="86.0" promptText="(i.e. 5.00 for $5.00)">
               <font>
                  <Font size="9.0" />
               </font>
            </TextField>
            <Label layoutX="20.0" layoutY="113.0" text="Amountt of Money Owed (in $)" />
            <ComboBox fx:id="enterState" layoutX="184.0" layoutY="166.0" prefHeight="25.0" prefWidth="100.0" promptText="Enter State" />
            <ComboBox fx:id="enterYearJoined" layoutX="303.0" layoutY="166.0" prefHeight="25.0" prefWidth="107.0" promptText="Year Joined" />
         </children>
      </AnchorPane>
   </children>
</AnchorPane>
Rahul Shah
  • 141
  • 2
  • 12
  • What do you mean by "the program crashes"? What happens? Is there an error message? – James_D Dec 01 '15 at 03:48
  • the window that says Java TM Platform SE Binary Is not responding and then it gives the options of closing the program or waiting for it to respond. – Rahul Shah Dec 01 '15 at 03:58
  • I tested your code (I had to make it into a complete example) and it worked fine for me. Can you adapt this code so that it is a [MCVE] that is complete and runnable and shows the problem? Also, what does `System.setProperty("glass.accessible.force", "false");` do? – James_D Dec 01 '15 at 04:02
  • that, i was told, fixes a glitch that exists in JavaFx apparently. See the thing is, is that it probably worked fine for you because you put it as a new project and that window was the only window that popped up. I have another window where i click a button and I open up the problem window in question. it is dependent on that first window. I'll see what I can do about making it more readily testable. – Rahul Shah Dec 01 '15 at 04:07
  • I probably won't be able to test it as it looks like a windows-only issue; however you should make it testable anyway. In case you haven't seen it, look at http://stackoverflow.com/questions/31786980/javafx-windows-10-combobox-error. As well as the system property there is a workaround with requesting focus. The bug report seems to indicate the fix was applied to JDK 8u66, so also try the latest version of the JDK. – James_D Dec 01 '15 at 04:12
  • I would also try setting that system property earlier in your application life cycle (in your `main` method, or at the very latest in your `start` method). – James_D Dec 01 '15 at 04:23
  • I dont know how but i broke my entire application. – Rahul Shah Dec 01 '15 at 04:35
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/96625/discussion-between-rahul-shah-and-james-d). – Rahul Shah Dec 01 '15 at 04:41

0 Answers0