Lukas
Lukas

Reputation: 120

java.lang.IllegalArgumentException: Cannot add the same item multiple times: Day@3ea2225f

I want to use a Treegrid to represent days, but when adding the days to the treegrid I get the error:

java.lang.IllegalArgumentException: Cannot add the same item multiple times: Day@3ea2225f

My setItems function looks like this:

this.tgridAppointments.setItems(lstDays, this::getChildDays);

private List<Day> getChildDays(Day d){
    return d.getAppointment().getDays().subList(1, d.getAppointment().getDays().size());
}

To understand this better. I got training appointments which then got a list of days where the training gets held. And in the TreeGrid I want to represent all the days of the appointment with the first day as root and the other days as children. The content of my Items looks like this:

lstDays.forEach(day -> {
            System.out.print(day.toString() + ": ");
            this.getChildDays(day).forEach(day2 -> System.out.print(day2.toString() + ", "));
            System.out.println();
        });

Output:
Day@407abaaf: Day@3ea2225f, Day@2b1858e6, Day@52179c9e
Day@21cf787b: Day@ed016c7
Output with .hashCode():
667947574: 1110372965, 1699219892, 1979719142, 
96167798: 817037438, 

So you can see every Item(Day) is unique, but I still get the error that the day gets added multiple times. The problem is when calling the setItems method the this::getChildDays method is called two times with the same root and I don't know why this happens. Hope someone can help me.

Upvotes: 3

Views: 273

Answers (1)

TomMathee
TomMathee

Reputation: 13

Shouldn't you index subList() from 0 to size ?

return d.getAppointment().getDays().subList(0, d.getAppointment().getDays().size());

Upvotes: 0

Related Questions