更改 JavaFX 选项卡顺序时出现 NullPointerException

Posted

技术标签:

【中文标题】更改 JavaFX 选项卡顺序时出现 NullPointerException【英文标题】:NullPointerException when changing JavaFX Tab Order 【发布时间】:2019-04-20 03:53:50 【问题描述】:

我从https://berry120.blogspot.com/2014/01/draggable-and-detachable-tabs-in-javafx.html 下载并试用了 Michael Berry 编写的 javafx 示例“JavaFX 2 中的可拖动和可拆卸选项卡”

它在 Java 8 中运行良好,但在 Java 11 和拼图模块中尝试它时就会崩溃。问题是,有时当我更改选项卡的顺序时,我得到一个 NullPointerException,即使在堆栈跟踪中也没有 fxtabs 类。

这是我的模块信息:

module fxtabs 
  exports fxtabs;

  requires javafx.base;
  requires javafx.graphics;
  requires transitive javafx.controls;

这是堆栈跟踪:

Exception in thread "JavaFX Application Thread" java.lang.NullPointerException
    at javafx.graphics/com.sun.javafx.scene.input.PickResultChooser.processOffer(PickResultChooser.java:185)
    at javafx.graphics/com.sun.javafx.scene.input.PickResultChooser.offer(PickResultChooser.java:143)
    at javafx.graphics/javafx.scene.Node.intersects(Node.java:5219)
    at javafx.graphics/javafx.scene.Node$1.intersects(Node.java:543)
    at javafx.graphics/com.sun.javafx.scene.NodeHelper.intersects(NodeHelper.java:258)
    at javafx.graphics/javafx.scene.layout.Region.doPickNodeLocal(Region.java:3161)
    at javafx.graphics/javafx.scene.layout.Region.access$600(Region.java:147)
    at javafx.graphics/javafx.scene.layout.Region$1.doPickNodeLocal(Region.java:184)
    at javafx.graphics/com.sun.javafx.scene.layout.RegionHelper.pickNodeLocalImpl(RegionHelper.java:104)
    at javafx.graphics/com.sun.javafx.scene.NodeHelper.pickNodeLocal(NodeHelper.java:128)
    at javafx.graphics/javafx.scene.Node.pickNode(Node.java:5192)
    at javafx.graphics/javafx.scene.Parent.pickChildrenNode(Parent.java:803)
    at javafx.graphics/javafx.scene.Parent$1.pickChildrenNode(Parent.java:136)
    at javafx.graphics/com.sun.javafx.scene.ParentHelper.pickChildrenNode(ParentHelper.java:113)
    at javafx.graphics/javafx.scene.layout.Region.doPickNodeLocal(Region.java:3160)
    at javafx.graphics/javafx.scene.layout.Region.access$600(Region.java:147)
    at javafx.graphics/javafx.scene.layout.Region$1.doPickNodeLocal(Region.java:184)
    at javafx.graphics/com.sun.javafx.scene.layout.RegionHelper.pickNodeLocalImpl(RegionHelper.java:104)
    at javafx.graphics/com.sun.javafx.scene.NodeHelper.pickNodeLocal(NodeHelper.java:128)
    at javafx.graphics/javafx.scene.Node.pickNode(Node.java:5192)
    at javafx.graphics/javafx.scene.Parent.pickChildrenNode(Parent.java:803)
    at javafx.graphics/javafx.scene.Parent$1.pickChildrenNode(Parent.java:136)
    at javafx.graphics/com.sun.javafx.scene.ParentHelper.pickChildrenNode(ParentHelper.java:113)
    at javafx.graphics/javafx.scene.layout.Region.doPickNodeLocal(Region.java:3160)
    at javafx.graphics/javafx.scene.layout.Region.access$600(Region.java:147)
    at javafx.graphics/javafx.scene.layout.Region$1.doPickNodeLocal(Region.java:184)
    at javafx.graphics/com.sun.javafx.scene.layout.RegionHelper.pickNodeLocalImpl(RegionHelper.java:104)
    at javafx.graphics/com.sun.javafx.scene.NodeHelper.pickNodeLocal(NodeHelper.java:128)
    at javafx.graphics/javafx.scene.Node.pickNode(Node.java:5192)
    at javafx.graphics/javafx.scene.Parent.pickChildrenNode(Parent.java:803)
    at javafx.graphics/javafx.scene.Parent$1.pickChildrenNode(Parent.java:136)
    at javafx.graphics/com.sun.javafx.scene.ParentHelper.pickChildrenNode(ParentHelper.java:113)
    at javafx.graphics/javafx.scene.layout.Region.doPickNodeLocal(Region.java:3160)
    at javafx.graphics/javafx.scene.layout.Region.access$600(Region.java:147)
    at javafx.graphics/javafx.scene.layout.Region$1.doPickNodeLocal(Region.java:184)
    at javafx.graphics/com.sun.javafx.scene.layout.RegionHelper.pickNodeLocalImpl(RegionHelper.java:104)
    at javafx.graphics/com.sun.javafx.scene.NodeHelper.pickNodeLocal(NodeHelper.java:128)
    at javafx.graphics/javafx.scene.Node.pickNode(Node.java:5192)
    at javafx.graphics/javafx.scene.Parent.pickChildrenNode(Parent.java:803)
    at javafx.graphics/javafx.scene.Parent$1.pickChildrenNode(Parent.java:136)
    at javafx.graphics/com.sun.javafx.scene.ParentHelper.pickChildrenNode(ParentHelper.java:113)
    at javafx.graphics/javafx.scene.layout.Region.doPickNodeLocal(Region.java:3160)
    at javafx.graphics/javafx.scene.layout.Region.access$600(Region.java:147)
    at javafx.graphics/javafx.scene.layout.Region$1.doPickNodeLocal(Region.java:184)
    at javafx.graphics/com.sun.javafx.scene.layout.RegionHelper.pickNodeLocalImpl(RegionHelper.java:104)
    at javafx.graphics/com.sun.javafx.scene.NodeHelper.pickNodeLocal(NodeHelper.java:128)
    at javafx.graphics/javafx.scene.Node.pickNode(Node.java:5192)
    at javafx.graphics/javafx.scene.Scene$MouseHandler.pickNode(Scene.java:3993)
    at javafx.graphics/javafx.scene.Scene$MouseHandler.access$1300(Scene.java:3579)
    at javafx.graphics/javafx.scene.Scene.pick(Scene.java:2029)
    at javafx.graphics/javafx.scene.Scene.access$6800(Scene.java:172)
    at javafx.graphics/javafx.scene.Scene$MouseHandler.process(Scene.java:3893)
    at javafx.graphics/javafx.scene.Scene$MouseHandler.access$1200(Scene.java:3579)
    at javafx.graphics/javafx.scene.Scene.processMouseEvent(Scene.java:1849)
    at javafx.graphics/javafx.scene.Scene$ScenePeerListener.mouseEvent(Scene.java:2588)
    at javafx.graphics/com.sun.javafx.tk.quantum.GlassViewEventHandler$MouseEventNotification.run(GlassViewEventHandler.java:397)
    at javafx.graphics/com.sun.javafx.tk.quantum.GlassViewEventHandler$MouseEventNotification.run(GlassViewEventHandler.java:295)
    at java.base/java.security.AccessController.doPrivileged(Native Method)
    at javafx.graphics/com.sun.javafx.tk.quantum.GlassViewEventHandler.lambda$handleMouseEvent$2(GlassViewEventHandler.java:434)
    at javafx.graphics/com.sun.javafx.tk.quantum.QuantumToolkit.runWithoutRenderLock(QuantumToolkit.java:390)
    at javafx.graphics/com.sun.javafx.tk.quantum.GlassViewEventHandler.handleMouseEvent(GlassViewEventHandler.java:433)
    at javafx.graphics/com.sun.glass.ui.View.handleMouseEvent(View.java:556)
    at javafx.graphics/com.sun.glass.ui.View.notifyMouse(View.java:942)
    at javafx.graphics/com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
    at javafx.graphics/com.sun.glass.ui.win.WinApplication.lambda$runLoop$3(WinApplication.java:174)
    at java.base/java.lang.Thread.run(Thread.java:834)

顺便说一句。用 try/catch 包围代码也无济于事。

【问题讨论】:

【参考方案1】:

第二天回到这个问题,这个问题神奇地消失了。我重新启动了计算机,现在我无法再重现异常。可能是 eclipse 或 jdk 中的一些错误——我不知道——但在它回来之前,我认为这个问题已经解决了。

【讨论】:

以上是关于更改 JavaFX 选项卡顺序时出现 NullPointerException的主要内容,如果未能解决你的问题,请参考以下文章

以编程方式使用选项卡更改片段的选项卡索引

visio流程图里,当我拖动流程边框时出现:由于形状保护和/或图层属性的设置,无法完全执行此命令。

由于启动计算机时出现了页面配置问题

JavaFX TabPane从外部控制器中选择选项卡

在 BottomNavigationView 中切换选项卡时出现延迟

在应用程序启动时预加载 UITabBar 选项卡时出现问题(崩溃)