选择项目时,Tableview会抛出索引超出范围的异常

时间:2018-01-09 03:02:24

标签: exception javafx tableview indexoutofboundsexception

我有一个JavaFX tableview。当我点击一行时,我收到一个例外。该异常不提供指向我的代码的指针,以指示我的错误可能位于何处。

这是selectedItem属性侦听器:

orderTable.getSelectionModel().selectedItemProperty().addListener(
        (observable, oldValue, newValue) -> {
            if (newValue != null) orderSelected();
        });

侦听器完成后发生异常。我只是通过从表中选择一个有效的可见项来找出为什么只生成一个索引越界异常的原因。

例外是:

08-01-18 21:31:12.871 ERROR java.lang.Throwable - Exception in thread "JavaFX Application Thread" java.lang.IndexOutOfBoundsException
08-01-18 21:31:12.874 ERROR java.lang.Throwable -   at com.sun.javafx.scene.control.ReadOnlyUnbackedObservableList.subList(ReadOnlyUnbackedObservableList.java:136)
08-01-18 21:31:12.875 ERROR java.lang.Throwable -   at javafx.collections.ListChangeListener$Change.getAddedSubList(ListChangeListener.java:242)
08-01-18 21:31:12.876 ERROR java.lang.Throwable -   at javafx.scene.control.TableView$TableViewArrayListSelectionModel.handleSelectedCellsListChangeEvent(TableView.java:3004)
08-01-18 21:31:12.876 ERROR java.lang.Throwable -   at javafx.scene.control.TableView$TableViewArrayListSelectionModel.clearAndSelect(TableView.java:2423)
08-01-18 21:31:12.876 ERROR java.lang.Throwable -   at javafx.scene.control.TableView$TableViewSelectionModel.clearAndSelect(TableView.java:1914)
08-01-18 21:31:12.876 ERROR java.lang.Throwable -   at com.sun.javafx.scene.control.behavior.TableCellBehaviorBase.simpleSelect(TableCellBehaviorBase.java:215)
08-01-18 21:31:12.876 ERROR java.lang.Throwable -   at com.sun.javafx.scene.control.behavior.TableCellBehaviorBase.doSelect(TableCellBehaviorBase.java:148)
08-01-18 21:31:12.877 ERROR java.lang.Throwable -   at com.sun.javafx.scene.control.behavior.CellBehaviorBase.mousePressed(CellBehaviorBase.java:150)
08-01-18 21:31:12.877 ERROR java.lang.Throwable -   at com.sun.javafx.scene.control.skin.BehaviorSkinBase$1.handle(BehaviorSkinBase.java:95)
08-01-18 21:31:12.878 ERROR java.lang.Throwable -   at com.sun.javafx.scene.control.skin.BehaviorSkinBase$1.handle(BehaviorSkinBase.java:89)
08-01-18 21:31:12.878 ERROR java.lang.Throwable -   at com.sun.javafx.event.CompositeEventHandler$NormalEventHandlerRecord.handleBubblingEvent(CompositeEventHandler.java:218)
08-01-18 21:31:12.878 ERROR java.lang.Throwable -   at com.sun.javafx.event.CompositeEventHandler.dispatchBubblingEvent(CompositeEventHandler.java:80)
08-01-18 21:31:12.878 ERROR java.lang.Throwable -   at com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:238)
08-01-18 21:31:12.879 ERROR java.lang.Throwable -   at com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:191)
08-01-18 21:31:12.879 ERROR java.lang.Throwable -   at com.sun.javafx.event.CompositeEventDispatcher.dispatchBubblingEvent(CompositeEventDispatcher.java:59)
08-01-18 21:31:12.879 ERROR java.lang.Throwable -   at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:58)
08-01-18 21:31:12.879 ERROR java.lang.Throwable -   at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
08-01-18 21:31:12.880 ERROR java.lang.Throwable -   at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)
08-01-18 21:31:12.880 ERROR java.lang.Throwable -   at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
08-01-18 21:31:12.880 ERROR java.lang.Throwable -   at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)
08-01-18 21:31:12.881 ERROR java.lang.Throwable -   at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
08-01-18 21:31:12.881 ERROR java.lang.Throwable -   at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)
08-01-18 21:31:12.881 ERROR java.lang.Throwable -   at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
08-01-18 21:31:12.881 ERROR java.lang.Throwable -   at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)
08-01-18 21:31:12.881 ERROR java.lang.Throwable -   at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
08-01-18 21:31:12.882 ERROR java.lang.Throwable -   at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)
08-01-18 21:31:12.882 ERROR java.lang.Throwable -   at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
08-01-18 21:31:12.883 ERROR java.lang.Throwable -   at com.sun.javafx.event.EventUtil.fireEventImpl(EventUtil.java:74)
08-01-18 21:31:12.883 ERROR java.lang.Throwable -   at com.sun.javafx.event.EventUtil.fireEvent(EventUtil.java:54)
08-01-18 21:31:12.883 ERROR java.lang.Throwable -   at javafx.event.Event.fireEvent(Event.java:198)
08-01-18 21:31:12.883 ERROR java.lang.Throwable -   at javafx.scene.Scene$MouseHandler.process(Scene.java:3757)
08-01-18 21:31:12.884 ERROR java.lang.Throwable -   at javafx.scene.Scene$MouseHandler.access$1500(Scene.java:3485)
08-01-18 21:31:12.884 ERROR java.lang.Throwable -   at javafx.scene.Scene.impl_processMouseEvent(Scene.java:1762)
08-01-18 21:31:12.884 ERROR java.lang.Throwable -   at javafx.scene.Scene$ScenePeerListener.mouseEvent(Scene.java:2494)
08-01-18 21:31:12.885 ERROR java.lang.Throwable -   at com.sun.javafx.tk.quantum.GlassViewEventHandler$MouseEventNotification.run(GlassViewEventHandler.java:381)
08-01-18 21:31:12.885 ERROR java.lang.Throwable -   at com.sun.javafx.tk.quantum.GlassViewEventHandler$MouseEventNotification.run(GlassViewEventHandler.java:295)
08-01-18 21:31:12.885 ERROR java.lang.Throwable -   at java.security.AccessController.doPrivileged(Native Method)
08-01-18 21:31:12.885 ERROR java.lang.Throwable -   at com.sun.javafx.tk.quantum.GlassViewEventHandler.lambda$handleMouseEvent$353(GlassViewEventHandler.java:417)
08-01-18 21:31:12.885 ERROR java.lang.Throwable -   at com.sun.javafx.tk.quantum.QuantumToolkit.runWithoutRenderLock(QuantumToolkit.java:389)
08-01-18 21:31:12.886 ERROR java.lang.Throwable -   at com.sun.javafx.tk.quantum.GlassViewEventHandler.handleMouseEvent(GlassViewEventHandler.java:416)
08-01-18 21:31:12.886 ERROR java.lang.Throwable -   at com.sun.glass.ui.View.handleMouseEvent(View.java:555)
08-01-18 21:31:12.886 ERROR java.lang.Throwable -   at com.sun.glass.ui.View.notifyMouse(View.java:937)
08-01-18 21:31:12.886 ERROR java.lang.Throwable -   at com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
08-01-18 21:31:12.887 ERROR java.lang.Throwable -   at com.sun.glass.ui.win.WinApplication.lambda$null$147(WinApplication.java:177)
08-01-18 21:31:12.888 ERROR java.lang.Throwable -   at java.lang.Thread.run(Thread.java:748)

1 个答案:

答案 0 :(得分:1)

我在试图提供最小,完整和可验证的问题时发现了这个问题。示例

表选择侦听器调用orderSelected():

    private void orderSelected() {
             clear();
             currentPurchaseOrder = orderTable.getSelectionModel().getSelectedItem();
             soldToCombo.getSelectionModel().select(currentPurchaseOrder.getCustomer());
...


private void clear() {
         currentPurchaseOrder = null;
         orderTable.getSelectionModel().clearSelection();

在clear()之后,任何更新表的操作(包括屏幕刷新)都会引发异常。