I have my scene made with JavaFX Scene Builder and ListView in it. I want it to show some data from xml file, but I have no idea how to properly initialize this ListView.
import javafx.collections.ObservableList;
import javafx.scene.control.ListView;
import application.Cparsing;
import javafx.collections.*;
public class MainDriversController{
private static ListView<String> driversLV;
static ObservableList<String> observableList = FXCollections.observableArrayList();
public static void SetListView(){
for(int x=0; x<Cparsing.driversNodes.getLength(); x++) {
observableList.add(Cparsing.driversNodes.item(x).getAttributes().getNamedItem("nick").getNodeValue());
}
driversLV.setItems(observableList);
System.out.println(driversLV);
}
}
That of course gives me NullPointerException because it's not initialized. I've tried to add
driversLV = new ListView<String>(observableList);
and no error then, but ListView is still empty in GUI.
System.out.println(driversLV);
gives:
ListView@54f2d1d5[styleClass=list-view]
So my question is: what is the proper way to initialize ListView? Is my code correct despite this?