0

I'm getting a NullPointerException when I try to populate my ComboBox, I have my class implementing Initializable.

    private ObservableList<String> incomeList = FXCollections.observableArrayList("Regular", "Other");
    private ObservableList<String> expenseList = FXCollections.observableArrayList("Food", "Entertainment", "Rent",
            "Bills", "Other");
@Override
public void initialize(URL location, ResourceBundle resources) {

    incomeComboBox.setItems(incomeList);

    expenseComboBox.setItems(expenseList);
}

I just want the ComboBoxes to be filled.

Thanks.

Rafael
  • 6,646
  • 13
  • 29
  • 43
Beez
  • 382
  • 3
  • 16
  • Well, for some reason `incomeComboBox` and/or `expenseComboBox` seem to be `null`. Impossible to tell what that reason is, since you did not post a [mcve] (The field declarations, root element and elements corresponding to the `ComboBox`es and possibly the way you load the fxml, if it's unusual, would be required to determine that.). – fabian May 02 '19 at 10:16

1 Answers1

0

The code you've shown seems alright. I assume you are using fxml files to create UI, problem could be you don't have fx:id associated with variable from your controller.

<ComboBox fx:id="incomeComboBox">

If u are using SceneBuilder, you should find this in the right menu, under Code tab.

peter nehila
  • 66
  • 1
  • 4