Reputation: 149
I want to transfer some dates as strings from an ObservableList to an ArrayList in java (JavaFX).
I have tried to use a for loop to add the data but it didn't work. Can you please help me with that. Thanks
This is my ObservableList
ObservableList<LocalDate> selectedDates = FXCollections.observableArrayList();
This is my ArrayList
static ArrayList<String> FinalDateArrayList;
I am filling the selectedDates ObservableList from the DatePicker so it works fine
startDatePicker.setOnAction(event -> selectedDates.add(startDatePicker.getValue()));
This is the for loop of transferring dates as string to my ArrayList
for(int i =0 ; i < selectedDates.size(); i++)
{
FinalDateArrayList.add(selectedDates.get(i).toString());
}
It didnt show me the error.
Upvotes: 1
Views: 2271
Reputation: 792
Initialize your FinalDateArrayList
with a non-null value
ArrayList<String> FinalDateArrayList = new ArrayList<String>();
Also, though not related to the question, use static
only if its really necessary.
Upvotes: 2