cancel
Showing results for 
Search instead for 
Did you mean: 

getting java.lang.UnsupportedOperationException while updating the existed values

former_member708417
Participant
0 Kudos

I have one item type, which has list of another items. I want to update the list of items in that item type, but getting the above error.

E.g

I have College Item Type -- which have List of Student Item Types.

While updating the College item type, i want to add new Student type to the existed list of Student types. But facing java.lang.UnsupportedOperationException.

college.getStudents().add(newStudent); -- This line giving error.

Any help will be appreciated. Thanks

Accepted Solutions (0)

Answers (1)

Answers (1)

bhavirisetty
Active Participant
0 Kudos

Hi,

The list you are trying to modify is unmodifiablelist , So you cannot modify the content of list. But you can do like below,

 List list=new ArrayList(college.getStudents());
 list.add(element);//add operation
 list.remove(elment)//remove operation
 
 college.setStudents(list);
 modelService.save(college)

Thanks