2 Replies Latest reply on Feb 5, 2013 8:19 PM by James_D

    Binds 2 Observable Lists throwing java.lang.UnsupportedOperationException

      Below is a simple code

      private ListProperty<String> list = new SimpleListProperty<>();
      private ListProperty<String> list2 = new SimpleListProperty<>();


      I want to bind both the Lists. But for some reason it throws: java.lang.UnsupportedOperationException at the Bindings Line.

      What is the issue with it?
        • 1. Re: Binds 2 Observable Lists throwing java.lang.UnsupportedOperationException
          Hi. The arguments (list1 and list2) should be observableList

          1 person found this helpful
          • 2. Re: Binds 2 Observable Lists throwing java.lang.UnsupportedOperationException
            SimpleListProperty implements ObservableList, so the types are just fine.

            The problem is that the default constructor new SimpleListProperty() creates a ListProperty that wraps an empty list; effectively it's equivalent to
            new SimpleListProperty(FXCollections.emptyObservableList());

            The list returned by FXCollections.emptyObservableList() is unmodifiable; the binding will attempt to call setAll(...) on one of the lists (passing the content of the other). Of course, an unmodifiable list will throw an UnsupportedOperationException when you try to set elements in it.

            You need to create the SimpleListProperty with a modifiable list:
            private ListProperty<String> list = new SimpleListProperty<>(FXCollections.<String>observableArrayList());
            private ListProperty<String> list2 = new SimpleListProperty<>(FXCollections.<String>observableArrayList());