0

I've got an NullPointerException which occures in this file:

Caused by: 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 sun.reflect.misc.Trampoline.invoke(Unknown Source)
at sun.reflect.GeneratedMethodAccessor1.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at sun.reflect.misc.MethodUtil.invoke(Unknown Source)
at javafx.fxml.FXMLLoader$MethodHandler.invoke(FXMLLoader.java:1771)
... 48 more
Caused by: java.lang.NullPointerException
at Controller.RocketController.addItem(RocketController.java:55)
at Controller.SurvayController.acceptButtonClicked(SurvayController.java:45)

Here is the part of code which probably is causing an error

RocketController:

    public void addItem(Aims aim)
    {
        ArrayList<Aims> list = new ArrayList();
        list.add(aim);
        ObservableList<Aims> observableList = FXCollections.observableList(list);
        listView.setItems(observableList);
    }

This function is triggered by a button in another stage:

SurvayController:

@FXML
void acceptButtonClicked()
{
    Aims newAim = new Aims(directionField.getText(),comboBox.getSelectionModel().getSelectedItem(),distanceField.getText(),speedField.getText());
    rocketController.addItem(newAim);
    Stage stage=(Stage) speedField.getScene().getWindow();
    stage.close();

}

Have you got any ideas why i get this ?

Mix1234
  • 11
  • 5
  • Looks to me like your RocketController object is null, ie, it was never instantiated with RocketController mycont = new RocketController(); or it wasn't yet instantiated when the button was clicked. – Alex Feb 17 '17 at 19:30
  • 1
    @AlexR If that were true, then the `addItem` method wouldn't get invoked. – James_D Feb 17 '17 at 19:31
  • Since you haven't told us which line is actually causing the exception, I assume you don't know how to diagnose a null pointer exception. Directing to a question that explains how. – James_D Feb 17 '17 at 19:32
  • After some lecture i still have no idea what is wrong. Debbuger says that line with **ObservableList observableList = FXCollections.observableList(list);** is cousing a problem – Mix1234 Feb 17 '17 at 20:06
  • When i step over this part of code i get the information "Source not found" – Mix1234 Feb 17 '17 at 20:08

0 Answers0