0

I am trying add items in my ComboBox, but I have the following error:

Exception in thread "JavaFX Application Thread" java.lang.IndexOutOfBoundsException: Index: 9, Size: 9
at java.util.ArrayList.rangeCheck(ArrayList.java:653)
at java.util.ArrayList.get(ArrayList.java:429)
at com.sun.javafx.collections.ObservableListWrapper.get(ObservableListWrapper.java:89)
at com.sun.javafx.collections.VetoableListDecorator.get(VetoableListDecorator.java:306)
at javafx.scene.Parent.layout(Parent.java:1091)
at javafx.scene.Scene.doLayoutPass(Scene.java:552)
at javafx.scene.Scene$ScenePulseListener.pulse(Scene.java:2397)
at com.sun.javafx.tk.Toolkit.lambda$runPulse$30(Toolkit.java:355)
at java.security.AccessController.doPrivileged(Native Method)
at com.sun.javafx.tk.Toolkit.runPulse(Toolkit.java:354)
at com.sun.javafx.tk.Toolkit.firePulse(Toolkit.java:381)
at com.sun.javafx.tk.quantum.QuantumToolkit.pulse(QuantumToolkit.java:510)
at com.sun.javafx.tk.quantum.QuantumToolkit.pulse(QuantumToolkit.java:490)
at com.sun.javafx.tk.quantum.QuantumToolkit.lambda$runToolkit$404(QuantumToolkit.java:319)
at com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:95)
at com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
at com.sun.glass.ui.win.WinApplication.lambda$null$148(WinApplication.java:191)
at java.lang.Thread.run(Thread.java:745)

See that no error leads to my implementation, only going to internal error. This is my code:

irParaCondicao.setOnFinished(event -> {
    processos.add(processoEmExecucao.getValue());
    processoEmExecucao.set(null);
});

processos.addListener((ListChangeListener<? super Processo>) c -> {
    if (c.next()) {
        validacaoD.getItems().clear();
        validacaoD.getItems().addAll(processosDeD);
    }
});

I already try to use this code inside javafx Thread, but the problem does not fix. Also I already looked about IndexOutOfBoundsException while updating a ListView in JavaFX without success. This hapens only the first time of the inclusion. Can someone help me?

fabian
  • 80,457
  • 12
  • 86
  • 114
  • `I already try to use this code inside javafx Thread` - doesn't seem like so. You need to find every single place where `processos` is modified, make sure *none* of them is in non-JavaFX Application Thread. – Jai May 22 '18 at 01:33
  • It looks like you are trying to `get` an element 9 from an arraylist that doesn't have 10 elements. For more help post more context [mcve]. Also mark the line that produces the error with a comment so we know. – c0der May 22 '18 at 02:57
  • There is not enough info to identify the problem. Without a [mcve] we won't be able to help. My guess would be that one of the items is removed from `processos` during the layout pass which results in the exception. – fabian May 22 '18 at 12:50

0 Answers0