【问题标题】:JavaFX TreeView java.lang.RuntimeExceptionJavaFX TreeView java.lang.RuntimeException
【发布时间】:2018-08-25 06:18:56
【问题描述】:

在运行一个演示 TreeView 控件使用的简单程序时出现以下异常:

java.lang.RuntimeException: 创建节点时出错:class javafx.scene.layout.StackPane id:null

在展开或关闭带有子项的 TreeItems 时发生错误。

这里是 SSCCE:

import static javafx.application.Application.launch;
import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.control.Tab;
import javafx.scene.control.TabPane;
import javafx.scene.control.TreeItem;
import javafx.scene.control.TreeView;
import javafx.stage.Stage;
public class TreeViewTest extends Application {
    Tab treeTab;
    @Override
    public void start(Stage primaryStage) throws Exception {
        TabPane pane = new TabPane();
        Scene scene = new Scene(pane,800,600);
        treeTab = new Tab("Tree");
        pane.getTabs().addAll(treeTab);
        primaryStage.setTitle("F(X)yz - Collision Test");
        primaryStage.setScene(scene);
        primaryStage.show();
        makeTree();
    }
    private void makeTree(){
        TreeItem<String> treeItemRoot = new TreeItem<> ("Root");         
        TreeItem<String> nodeItemA = new TreeItem<>("Item A");
        TreeItem<String> nodeItemB = new TreeItem<>("Item B");
        TreeItem<String> nodeItemC = new TreeItem<>("Item C");
        treeItemRoot.getChildren().addAll(nodeItemA, nodeItemB, nodeItemC);        
        TreeItem<String> nodeItemCA = new TreeItem<>("Item CA");
        TreeItem<String> nodeItemCB = new TreeItem<>("Item CB");
        nodeItemC.getChildren().addAll(nodeItemCA, nodeItemCB);         
        TreeItem<String> nodeItemA1 = new TreeItem<>("Item A1");
        TreeItem<String> nodeItemA2 = new TreeItem<>("Item A2");
        TreeItem<String> nodeItemA3 = new TreeItem<>("Item A3");
        nodeItemA.getChildren().addAll(nodeItemA1, nodeItemA2, nodeItemA3);         
        TreeView<String> treeView = new TreeView<>(treeItemRoot);
        treeTab.setContent(treeView);        
    }        
     public static void main(String[] args) {
        launch(args);
    }
}

这是在 Windows 7 上的 Netbeans 8.2 中的 jdk1.8.0_162 上运行的。

请任何人提出改进以消除错误。 谢谢。

PS StackTrace:

java.lang.RuntimeException: Error while creating node:class javafx.scene.layout.StackPane id:null
NODE INFORMATION
Node:StackPane@5bb0a705[styleClass=tree-disclosure-node] Class:class javafx.scene.layout.StackPane Id:null
Children:[StackPane@401249ef[styleClass=arrow]]
PARENT INFORMATION
Node:TreeViewSkin$1@72fac9c9[styleClass=cell indexed-cell tree-cell]'Root' Class:class com.sun.javafx.scene.control.skin.TreeViewSkin$1 Id:null
Children:[Text[text="Root", x=0.0, y=0.0, alignment=LEFT, origin=BASELINE, boundsType=LOGICAL_VERTICAL_CENTER, font=Font[name=System Regular, family=System, style=Regular, size=15.0], fontSmoothingType=LCD, fill=0x333333ff]]

    at org.fxconnector.node.SVNodeFactory.createNode(SVNodeFactory.java:56)
    at org.fxconnector.StageControllerImpl.createNode(StageControllerImpl.java:775)
    at org.fxconnector.StageControllerImpl.lambda$new$10(StageControllerImpl.java:231)
    at com.sun.javafx.collections.ListListenerHelper$Generic.fireValueChangedEvent(ListListenerHelper.java:329)
    at com.sun.javafx.collections.ListListenerHelper.fireValueChangedEvent(ListListenerHelper.java:73)
    at javafx.collections.ObservableListBase.fireChange(ObservableListBase.java:233)
    at javafx.collections.FXCollections$UnmodifiableObservableListImpl.lambda$new$62(FXCollections.java:929)
    at javafx.collections.WeakListChangeListener.onChanged(WeakListChangeListener.java:88)
    at com.sun.javafx.collections.ListListenerHelper$SingleChange.fireValueChangedEvent(ListListenerHelper.java:164)
    at com.sun.javafx.collections.ListListenerHelper.fireValueChangedEvent(ListListenerHelper.java:73)
    at com.sun.javafx.collections.VetoableListDecorator.lambda$new$31(VetoableListDecorator.java:76)
    at com.sun.javafx.collections.ListListenerHelper$Generic.fireValueChangedEvent(ListListenerHelper.java:329)
    at com.sun.javafx.collections.ListListenerHelper.fireValueChangedEvent(ListListenerHelper.java:73)
    at javafx.collections.ObservableListBase.fireChange(ObservableListBase.java:233)
    at javafx.collections.ListChangeBuilder.commit(ListChangeBuilder.java:482)
    at javafx.collections.ListChangeBuilder.endChange(ListChangeBuilder.java:541)
    at javafx.collections.ObservableListBase.endChange(ObservableListBase.java:205)
    at javafx.collections.ModifiableObservableListBase.remove(ModifiableObservableListBase.java:183)
    at com.sun.javafx.collections.VetoableListDecorator.remove(VetoableListDecorator.java:332)
    at com.sun.javafx.collections.VetoableListDecorator.remove(VetoableListDecorator.java:221)
    at javafx.scene.Parent.impl_toBack(Parent.java:644)
    at javafx.scene.Node.toBack(Node.java:1756)
    at com.sun.javafx.scene.control.skin.TreeCellSkin.updateDisclosureNode(TreeCellSkin.java:186)
    at com.sun.javafx.scene.control.skin.TreeCellSkin.layoutChildren(TreeCellSkin.java:211)
    at javafx.scene.control.Control.layoutChildren(Control.java:578)
    at javafx.scene.Parent.layout(Parent.java:1087)
    at javafx.scene.Parent.layout(Parent.java:1093)
    at javafx.scene.Parent.layout(Parent.java:1093)
    at javafx.scene.Parent.layout(Parent.java:1093)
    at javafx.scene.Parent.layout(Parent.java:1093)
    at javafx.scene.Parent.layout(Parent.java:1093)
    at javafx.scene.Parent.layout(Parent.java:1093)
    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$29(Toolkit.java:398)
    at java.security.AccessController.doPrivileged(Native Method)
    at com.sun.javafx.tk.Toolkit.runPulse(Toolkit.java:397)
    at com.sun.javafx.tk.Toolkit.firePulse(Toolkit.java:424)
    at com.sun.javafx.tk.quantum.QuantumToolkit.pulse(QuantumToolkit.java:518)
    at com.sun.javafx.tk.quantum.QuantumToolkit.pulse(QuantumToolkit.java:498)
    at com.sun.javafx.tk.quantum.QuantumToolkit.pulseFromQueue(QuantumToolkit.java:491)
    at com.sun.javafx.tk.quantum.QuantumToolkit.lambda$runToolkit$403(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$147(WinApplication.java:177)
    at java.lang.Thread.run(Thread.java:748)
java.lang.RuntimeException: Error while creating node:class javafx.scene.layout.StackPane id:null
NODE INFORMATION
Node:StackPane@3fb4f2e2[styleClass=tree-disclosure-node] Class:class javafx.scene.layout.StackPane Id:null
Children:[StackPane@b52262b[styleClass=arrow]]
PARENT INFORMATION
Node:TreeViewSkin$1@330b4596[styleClass=cell indexed-cell tree-cell]'Item A' Class:class com.sun.javafx.scene.control.skin.TreeViewSkin$1 Id:null
Children:[Text[text="", x=0.0, y=0.0, alignment=LEFT, origin=BASELINE, boundsType=LOGICAL_VERTICAL_CENTER, font=Font[name=System Regular, family=System, style=Regular, size=15.0], fontSmoothingType=LCD, fill=0x333333ff]]

    at org.fxconnector.node.SVNodeFactory.createNode(SVNodeFactory.java:56)
    at org.fxconnector.StageControllerImpl.createNode(StageControllerImpl.java:775)
    at org.fxconnector.StageControllerImpl.lambda$new$10(StageControllerImpl.java:231)
    at com.sun.javafx.collections.ListListenerHelper$Generic.fireValueChangedEvent(ListListenerHelper.java:329)
    at com.sun.javafx.collections.ListListenerHelper.fireValueChangedEvent(ListListenerHelper.java:73)
    at javafx.collections.ObservableListBase.fireChange(ObservableListBase.java:233)
    at javafx.collections.FXCollections$UnmodifiableObservableListImpl.lambda$new$62(FXCollections.java:929)
    at javafx.collections.WeakListChangeListener.onChanged(WeakListChangeListener.java:88)
    at com.sun.javafx.collections.ListListenerHelper$SingleChange.fireValueChangedEvent(ListListenerHelper.java:164)
    at com.sun.javafx.collections.ListListenerHelper.fireValueChangedEvent(ListListenerHelper.java:73)
    at com.sun.javafx.collections.VetoableListDecorator.lambda$new$31(VetoableListDecorator.java:76)
    at com.sun.javafx.collections.ListListenerHelper$Generic.fireValueChangedEvent(ListListenerHelper.java:329)
    at com.sun.javafx.collections.ListListenerHelper.fireValueChangedEvent(ListListenerHelper.java:73)
    at javafx.collections.ObservableListBase.fireChange(ObservableListBase.java:233)
    at javafx.collections.ListChangeBuilder.commit(ListChangeBuilder.java:482)
    at javafx.collections.ListChangeBuilder.endChange(ListChangeBuilder.java:541)
    at javafx.collections.ObservableListBase.endChange(ObservableListBase.java:205)
    at javafx.collections.ModifiableObservableListBase.remove(ModifiableObservableListBase.java:183)
    at com.sun.javafx.collections.VetoableListDecorator.remove(VetoableListDecorator.java:332)
    at com.sun.javafx.collections.VetoableListDecorator.remove(VetoableListDecorator.java:221)
    at javafx.scene.Parent.impl_toBack(Parent.java:644)
    at javafx.scene.Node.toBack(Node.java:1756)
    at com.sun.javafx.scene.control.skin.TreeCellSkin.updateDisclosureNode(TreeCellSkin.java:186)
    at com.sun.javafx.scene.control.skin.TreeCellSkin.layoutChildren(TreeCellSkin.java:211)
    at javafx.scene.control.Control.layoutChildren(Control.java:578)
    at javafx.scene.Parent.layout(Parent.java:1087)
    at javafx.scene.Parent.layout(Parent.java:1093)
    at javafx.scene.Parent.layout(Parent.java:1093)
    at javafx.scene.Parent.layout(Parent.java:1093)
    at javafx.scene.Parent.layout(Parent.java:1093)
    at javafx.scene.Parent.layout(Parent.java:1093)
    at javafx.scene.Parent.layout(Parent.java:1093)
    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$29(Toolkit.java:398)
    at java.security.AccessController.doPrivileged(Native Method)
    at com.sun.javafx.tk.Toolkit.runPulse(Toolkit.java:397)
    at com.sun.javafx.tk.Toolkit.firePulse(Toolkit.java:424)
    at com.sun.javafx.tk.quantum.QuantumToolkit.pulse(QuantumToolkit.java:518)
    at com.sun.javafx.tk.quantum.QuantumToolkit.pulse(QuantumToolkit.java:498)
    at com.sun.javafx.tk.quantum.QuantumToolkit.pulseFromQueue(QuantumToolkit.java:491)
    at com.sun.javafx.tk.quantum.QuantumToolkit.lambda$runToolkit$403(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$147(WinApplication.java:177)
    at java.lang.Thread.run(Thread.java:748)
java.lang.RuntimeException: Error while creating node:class javafx.scene.layout.StackPane id:null
NODE INFORMATION
Node:StackPane@4a2a9995[styleClass=tree-disclosure-node] Class:class javafx.scene.layout.StackPane Id:null
Children:[StackPane@5483de69[styleClass=arrow]]
PARENT INFORMATION
Node:TreeViewSkin$1@269becf3[styleClass=cell indexed-cell tree-cell]'Item C' Class:class com.sun.javafx.scene.control.skin.TreeViewSkin$1 Id:null
Children:[Text[text="", x=0.0, y=0.0, alignment=LEFT, origin=BASELINE, boundsType=LOGICAL_VERTICAL_CENTER, font=Font[name=System Regular, family=System, style=Regular, size=15.0], fontSmoothingType=LCD, fill=0x333333ff]]

    at org.fxconnector.node.SVNodeFactory.createNode(SVNodeFactory.java:56)
    at org.fxconnector.StageControllerImpl.createNode(StageControllerImpl.java:775)
    at org.fxconnector.StageControllerImpl.lambda$new$10(StageControllerImpl.java:231)
    at com.sun.javafx.collections.ListListenerHelper$Generic.fireValueChangedEvent(ListListenerHelper.java:329)
    at com.sun.javafx.collections.ListListenerHelper.fireValueChangedEvent(ListListenerHelper.java:73)
    at javafx.collections.ObservableListBase.fireChange(ObservableListBase.java:233)
    at javafx.collections.FXCollections$UnmodifiableObservableListImpl.lambda$new$62(FXCollections.java:929)
    at javafx.collections.WeakListChangeListener.onChanged(WeakListChangeListener.java:88)
    at com.sun.javafx.collections.ListListenerHelper$SingleChange.fireValueChangedEvent(ListListenerHelper.java:164)
    at com.sun.javafx.collections.ListListenerHelper.fireValueChangedEvent(ListListenerHelper.java:73)
    at com.sun.javafx.collections.VetoableListDecorator.lambda$new$31(VetoableListDecorator.java:76)
    at com.sun.javafx.collections.ListListenerHelper$Generic.fireValueChangedEvent(ListListenerHelper.java:329)
    at com.sun.javafx.collections.ListListenerHelper.fireValueChangedEvent(ListListenerHelper.java:73)
    at javafx.collections.ObservableListBase.fireChange(ObservableListBase.java:233)
    at javafx.collections.ListChangeBuilder.commit(ListChangeBuilder.java:482)
    at javafx.collections.ListChangeBuilder.endChange(ListChangeBuilder.java:541)
    at javafx.collections.ObservableListBase.endChange(ObservableListBase.java:205)
    at javafx.collections.ModifiableObservableListBase.remove(ModifiableObservableListBase.java:183)
    at com.sun.javafx.collections.VetoableListDecorator.remove(VetoableListDecorator.java:332)
    at com.sun.javafx.collections.VetoableListDecorator.remove(VetoableListDecorator.java:221)
    at javafx.scene.Parent.impl_toBack(Parent.java:644)
    at javafx.scene.Node.toBack(Node.java:1756)
    at com.sun.javafx.scene.control.skin.TreeCellSkin.updateDisclosureNode(TreeCellSkin.java:186)
    at com.sun.javafx.scene.control.skin.TreeCellSkin.layoutChildren(TreeCellSkin.java:211)
    at javafx.scene.control.Control.layoutChildren(Control.java:578)
    at javafx.scene.Parent.layout(Parent.java:1087)
    at javafx.scene.Parent.layout(Parent.java:1093)
    at javafx.scene.Parent.layout(Parent.java:1093)
    at javafx.scene.Parent.layout(Parent.java:1093)
    at javafx.scene.Parent.layout(Parent.java:1093)
    at javafx.scene.Parent.layout(Parent.java:1093)
    at javafx.scene.Parent.layout(Parent.java:1093)
    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$29(Toolkit.java:398)
    at java.security.AccessController.doPrivileged(Native Method)
    at com.sun.javafx.tk.Toolkit.runPulse(Toolkit.java:397)
    at com.sun.javafx.tk.Toolkit.firePulse(Toolkit.java:424)
    at com.sun.javafx.tk.quantum.QuantumToolkit.pulse(QuantumToolkit.java:518)
    at com.sun.javafx.tk.quantum.QuantumToolkit.pulse(QuantumToolkit.java:498)
    at com.sun.javafx.tk.quantum.QuantumToolkit.pulseFromQueue(QuantumToolkit.java:491)
    at com.sun.javafx.tk.quantum.QuantumToolkit.lambda$runToolkit$403(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$147(WinApplication.java:177)
    at java.lang.Thread.run(Thread.java:748)

【问题讨论】:

  • hmm ... 8_151 和 9_01 中的工作表 - 预计 8_161 中不会出现“中间”不当行为。另一方面:依稀记得最近在 treeView 周围看到了一个奇怪的错误,但找不到它......你能添加堆栈跟踪吗?
  • 这让我很担心,所以我将文件复制到一个“干净的项目”中 - 运行它时仍然出现错误。然而,谷歌搜索 org.fxconnector.node.SVNodeFactory 让我找到了 ScenicView 源代码。然后我记得我有 ScenicView 正在运行!!!
  • 关闭 ScenicView 后,测试程序现在可以按预期运行。谢谢你的评论。我仍然认为这可能是一个错误,因为我认为 ScenicView 不应该导致 RuntimeException。
  • 很高兴你找到了原因 :) 很可能是一个错误,我怀疑 ScenicView 是罪魁祸首...
  • 只是为了确认,这里有完全相同的问题。在 linux 下运行 Javafx 11.0.2 并且还看到了堆栈跟踪。我还在后台运行了 ScenicView。关闭它,堆栈跟踪就消失了! :) 感谢@jimbo8 带我去看它 :)

标签: javafx treeview


【解决方案1】:

我也遇到过,所以我将@jimbo8的评论作为答案:

这是由ScenicView引起的。

关闭 ScenicView,您将不会再收到此错误。

【讨论】:

    猜你喜欢
    • 2015-11-01
    • 2017-01-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-12-16
    • 1970-01-01
    • 2018-01-12
    • 2013-03-25
    相关资源
    最近更新 更多