IllegalStateException on an observable list
Jonathan Giles
jonathan.giles at oracle.com
Sun Oct 21 13:12:42 PDT 2012
This is a common mistake. You must, inside the onChanged method, loop
through the changes as such:
while (changes.next()) {
// put your for loop here
}
I agree the exception is not clear - I would love to see an improved
error message in the exception to clarify what people need to do.
-- Jonathan
On 22/10/2012 8:37 a.m., Tom Eugelink wrote:
> I have two observable lists; one containing appointments, the other
> containing selected appointments. If an appointment is removed from
> the first list, it also must be removed from the second. For this I
> setup a listener on the first list to handle this:
>
> // when appointments are removed, they can't be selected anymore
> appointments.addListener(new
> ListChangeListener<Agenda.Appointment>()
> {
> @Override
> public void
> onChanged(javafx.collections.ListChangeListener.Change<? extends
> Appointment> changes)
> {
> for (Appointment lAppointment : changes.getRemoved())
> {
> selectedAppointments.remove(lAppointment);
> }
> }
> });
>
> when constructing the control I get the following exception on the
> getRemoved() call.
>
> Caused by: java.lang.IllegalStateException
> at
> com.sun.javafx.collections.NonIterableChange.checkState(NonIterableChange.java:101)
> at
> com.sun.javafx.collections.NonIterableChange$SimpleAddChange.getRemoved(NonIterableChange.java:158)
> at jfxtras.labs.scene.control.Agenda$1.onChanged(Agenda.java:108)
> at
> com.sun.javafx.collections.ListListenerHelper$SingleChange.fireValueChangedEvent(ListListenerHelper.java:134)
> at
> com.sun.javafx.collections.ListListenerHelper.fireValueChangedEvent(ListListenerHelper.java:48)
> at
> com.sun.javafx.collections.ObservableListWrapper.callObservers(ObservableListWrapper.java:97)
> at
> com.sun.javafx.collections.ObservableListWrapper.addAll(ObservableListWrapper.java:171)
> at
> com.sun.javafx.collections.ObservableListWrapper.addAll(ObservableListWrapper.java:160)
> at
> com.sun.javafx.collections.ObservableListWrapper.addAll(ObservableListWrapper.java:309)
> at
> jfxtras.labs.scene.control.AgendaTrial1.start(AgendaTrial1.java:122)
> at
> com.sun.javafx.application.LauncherImpl$5.run(LauncherImpl.java:319)
> at
> com.sun.javafx.application.PlatformImpl$5.run(PlatformImpl.java:206)
> at
> com.sun.javafx.application.PlatformImpl$4.run(PlatformImpl.java:173)
> at com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
> at
> com.sun.glass.ui.win.WinApplication.access$100(WinApplication.java:29)
> at
> com.sun.glass.ui.win.WinApplication$2$1.run(WinApplication.java:62)
> ... 1 more
>
> Can someone explain why? And how to work around that?
>
> Tom
>
>
More information about the openjfx-dev
mailing list