0

I am receiving a null pointer exception and I am not sure why. I have this function that is called when a button is pressed:

@FXML
private void handlePlayButton(ActionEvent e) {

    for(Node child:getCenterPaneUndirectedNonWeightedGraph().getChildren()) {
        if(child instanceof StackPane) {
            StackPane vertex = (StackPane) child;
            System.out.println(vertex == null);
            bfs.fillVertexTransition(vertex);
        }
    }

}

My print statement 'System.out.println(vertex == null);' prints false.

I get the null pointer exception at the line:

bfs.fillVertexTransition(vertex);

The method 'fillVertexTransition' is defined by:

public void fillVertexTransition(StackPane vertex) {
    Circle circle = (Circle) vertex.getChildren().get(0);

    FillTransition ft = new FillTransition(Duration.millis(3000), circle, Color.RED, Color.BLUE);
    ft.play();

}  

In my application the StackPanes are circles with a label on top of the circle.

Any way I can fix this?

Thank you.

Jaman
  • 125
  • 1
  • 11
  • 2
    it might be that bfs is null. it might be that something within that method throws the NPE. look at the stacktrace and figure out what line throws the Exception firstµ – Stultuske Jan 17 '19 at 14:17
  • 1
    Yup thats it I forgot to initialise the bfs object *FacePalm*. Thank you – Jaman Jan 17 '19 at 14:19

0 Answers0