首页 > 解决方案 > 当 BorderPane.setLeft 出现 IndexOutOfBoundsException

问题描述

当我尝试在 BorderPane 中执行 setLeft 时,有时会出现错误。问题来自以下行:

bpDetail.setLeft(selected ? ivSelected : null);

我想在borderPane左侧选择某些东西时绘制图像,但有时程序会抛出以下错误:

Caused by: java.lang.IndexOutOfBoundsException: Index: 3, Size: 3
    at java.util.ArrayList.rangeCheck(ArrayList.java:657)
    at java.util.ArrayList.get(ArrayList.java:433)
    at com.sun.javafx.collections.ObservableListWrapper.get(ObservableListWrapper.java:89)
    at com.sun.javafx.collections.VetoableListDecorator.get(VetoableListDecorator.java:306)
    at javafx.scene.Parent$2.onProposedChange(Parent.java:423)
    at com.sun.javafx.collections.VetoableListDecorator.remove(VetoableListDecorator.java:329)
    at com.sun.javafx.collections.VetoableListDecorator.remove(VetoableListDecorator.java:221)
    at javafx.scene.layout.BorderPane$BorderPositionProperty.invalidated(BorderPane.java:673)
    at javafx.beans.property.ObjectPropertyBase.markInvalid(ObjectPropertyBase.java:111)
    at javafx.beans.property.ObjectPropertyBase.set(ObjectPropertyBase.java:146)
    at javafx.scene.layout.BorderPane.setLeft(BorderPane.java:314)
    at main.Selectable.showSelected(Selectable.java:594)
    at main.Selectable.initialize(Selectable.java:300)
    at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:2548)
    ... 14 more

有谁明白为什么有时会发生这种情况?

提前致谢!

标签: javajavafxborderpane

解决方案


推荐阅读