I want to gather what's in one listview. Write that information to a file. Read the file and display it's contents back into another listview. Currently I am struggling with accessing a listview in another class to be able to iterate through it and write to a file. Listview "temp" is returning null.
public void writeToFile(String file, Controller controller) throws IOException {
FileWriter fw = new FileWriter(file, true);
BufferedWriter bw = new BufferedWriter(fw);
ListView<Items> temp = controller.getListtaking();
System.out.print(temp);
for (int i = 0; i < temp.getItems().size(); i++) {
bw.write(temp.getItems().get(i) + ",\r");
}
bw.write(totalorder+ "\r");
bw.write(";\r");
bw.close();
}
// This is one class
Controller controller;
public ListView<Items> getListtaking() {
return listtaking;
}
public void OrderIn(ActionEvent actionEvent) throws IOException {
Orders orderin = new Orders(total);
totalorder = total;
System.out.println(orderin.totalcost);
System.out.println(orderin);
System.out.println(listtaking.getItems());
listcurrent.getItems().add(orderin);
listorder = listtaking;
String FileName = String.valueOf(Orders.ordernumber);
new File(FileName + ".txt");
ObservableList<Items> myList = listtaking.getItems();
for (Items i : myList) {
i.writeToFile(FileName,controller);
}
listtaking.getItems().clear(); // This is another class
`