我从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 包围代码也无济于事。