nus-cs2103-AY2223S2 / forum

12 stars 0 forks source link

InvocationTargetException when sorting ObservableList<User> #285

Closed adam07018 closed 1 year ago

adam07018 commented 1 year ago

Hello everyone. I am trying to implement sort feature for tp. I get stuck when I try to sort ObservableList in a command class

  1. I wrap ObservableList in sortedList

SortedList<User> lastShownList = new SortedList<>(model.getFilteredUserList());;

  1. Sort user based on their user name in lexicographical order.

lastShownList.sort(Comparator.comparing(User::toString));

However, after executing step 2, it jumps out InvocationTargetException in FXML Loader#Method Handler

Does anyone have any thoughts why this happen? Please give any possible suggestions!

damithc commented 1 year ago

@adam07018 It might help if you push your branch to your fork and share the link here so that others can look at the exact code.

Out of curiosity, I asked ChatGPT the same question and this is what it had to say: image

damithc commented 1 year ago

@adam07018 were you able to resolve? how?

adam07018 commented 1 year ago

@damithc SFLR Prof.

I just deep copy every user into a new list. I guess there are some restrictions in javaFX. Which stops me from directly make change on ObservableList.

But with javaFX it works, it's weird.