I created a ListView with three options in it and I want to draw a triangle with a certain color depending on what option in the ListView that is selected.
String vald = categoryList.getSelectionModel().getSelectedItem();
Triangle triangle = new Triangle(x,y);
if(vald.equals("Bus")) {
triangle.setFill(Color.BLACK);
}
else {
triangle.setFill(Color.YELLOW);
}
center.getChildren().add(triangle);
It works when I select any of the three options. Problem is when I start up the program and dont select anything in the List, it gives me a nullpointer exception and points to the vald.equals("Bus") and the package declaration. When I remove the code for the listview check it works tho. So I'm wondering if I'm missing something when checking for items in a ListView. (I checked if it worked with radiobuttons instead and it did so I'm at a dead end)