使用自定义组件时,Scenebuilder引发nullpointer异常

时间:2018-07-27 08:56:32

标签: javafx groovy scenebuilder

我有一个这样的自定义组件:

class SelectableVBox extends VBox {
Node selectedNode
private static PseudoClass selected = PseudoClass.getPseudoClass("selected")

SelectableVBox() {
    super()


    addEventFilter(MouseEvent.MOUSE_CLICKED, { MouseEvent event ->
        if (event.button == MouseButton.PRIMARY) {
            def intersectedNode = NodeUtility.firstParentFullfilling(event.pickResult.intersectedNode, { node -> children.contains(node) })
            if (intersectedNode == null) {
                return
            }
            if (selectedNode != null) {
                selectedNode.pseudoClassStateChanged(selected, false)
            }
            selectedNode = intersectedNode
            selectedNode.pseudoClassStateChanged(selected, true)
        }
    })
}

}

基本上是一个VBox,它实现了一个非常轻便的选择模型,然后可以用来访问当前选定的节点。

我现在将这个组件以及其他3个组件导出到一个jarfile中,并正确地将其导入Scenebuilder中。 所有其他组件都可以工作,尽管在fxml文件中拥有此组件会导致以下异常,这会导致SceneBuilder本身在打开时抛出整个SceneBuilder屏幕空白:

Jul 27, 2018 10:50:21 AM 

com.oracle.javafx.scenebuilder.app.SceneBuilderApp$SceneBuilderUncaughtExceptionHandler uncaughtException
SEVERE: An exception was thrown:
java.lang.NullPointerException
        at com.sun.javafx.css.StyleManager.lambda$loadStylesheetUnPrivileged$191(StyleManager.java:1060)
        at java.security.AccessController.doPrivileged(Native Method)
        at com.sun.javafx.css.StyleManager.loadStylesheetUnPrivileged(StyleManager.java:1054)
        at com.sun.javafx.css.StyleManager.loadStylesheet(StyleManager.java:935)
        at com.sun.javafx.css.StyleManager.processStylesheets(StyleManager.java:1556)
        at com.sun.javafx.css.StyleManager.gatherParentStylesheets(StyleManager.java:1597)
        at com.sun.javafx.css.StyleManager.findMatchingStyles(StyleManager.java:1659)
        at javafx.scene.CssStyleHelper.createStyleHelper(CssStyleHelper.java:111)
        at javafx.scene.Node.reapplyCss(Node.java:8985)
        at javafx.scene.Node.reapplyCss(Node.java:9014)
        at javafx.scene.Node.reapplyCss(Node.java:9014)
        at javafx.scene.Node.impl_reapplyCSS(Node.java:8948)
        at javafx.scene.Node.invalidatedScenes(Node.java:856)
        at javafx.scene.Node.setScenes(Node.java:921)
        at javafx.scene.Parent$1.onChanged(Parent.java:269)
        at com.sun.javafx.collections.TrackableObservableList.lambda$new$29(TrackableObservableList.java:45)
        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.addAll(ModifiableObservableListBase.java:102)
        at com.sun.javafx.collections.VetoableListDecorator.addAll(VetoableListDecorator.java:237)
        at com.sun.javafx.collections.VetoableListDecorator.addAll(VetoableListDecorator.java:103)
        at com.sun.javafx.scene.control.skin.ScrollPaneSkin.initialize(ScrollPaneSkin.java:312)
        at com.sun.javafx.scene.control.skin.ScrollPaneSkin.<init>(ScrollPaneSkin.java:125)
        at javafx.scene.control.ScrollPane.createDefaultSkin(ScrollPane.java:635)
        at javafx.scene.control.Control.impl_processCSS(Control.java:872)
        at javafx.scene.Parent.impl_processCSS(Parent.java:1280)
        at javafx.scene.Parent.impl_processCSS(Parent.java:1280)
        at javafx.scene.Parent.impl_processCSS(Parent.java:1280)
        at javafx.scene.Parent.impl_processCSS(Parent.java:1280)
        at javafx.scene.Node.processCSS(Node.java:9058)
        at javafx.scene.Node.applyCss(Node.java:9155)
        at com.oracle.javafx.scenebuilder.kit.editor.panel.content.WorkspaceController.layoutContent(WorkspaceController.java:227)
        at com.oracle.javafx.scenebuilder.kit.editor.panel.content.WorkspaceController.updateContentGroup(WorkspaceController.java:340)
        at com.oracle.javafx.scenebuilder.kit.editor.panel.content.WorkspaceController.sceneGraphDidChange(WorkspaceController.java:126)
        at com.oracle.javafx.scenebuilder.kit.editor.panel.content.WorkspaceController.setFxomDocument(WorkspaceController.java:120)
        at com.oracle.javafx.scenebuilder.kit.editor.panel.content.ContentPanelController.fxomDocumentDidChange(ContentPanelController.java:745)
        at com.oracle.javafx.scenebuilder.kit.editor.panel.util.AbstractPanelController.lambda$new$0(AbstractPanelController.java:90)
        at com.sun.javafx.binding.ExpressionHelper$Generic.fireValueChangedEvent(ExpressionHelper.java:361)
        at com.sun.javafx.binding.ExpressionHelper.fireValueChangedEvent(ExpressionHelper.java:81)
        at javafx.beans.property.ObjectPropertyBase.fireValueChangedEvent(ObjectPropertyBase.java:105)
        at javafx.beans.property.ObjectPropertyBase.markInvalid(ObjectPropertyBase.java:112)
        at javafx.beans.property.ObjectPropertyBase.set(ObjectPropertyBase.java:146)
        at javafx.beans.property.ObjectProperty.setValue(ObjectProperty.java:69)
        at com.oracle.javafx.scenebuilder.kit.editor.EditorController.updateFxomDocument(EditorController.java:2548)
        at com.oracle.javafx.scenebuilder.kit.editor.EditorController.setFxmlTextAndLocation(EditorController.java:761)
        at com.oracle.javafx.scenebuilder.app.DocumentWindowController.loadFromFile(DocumentWindowController.java:385)
        at com.oracle.javafx.scenebuilder.app.SceneBuilderApp.performOpenFiles(SceneBuilderApp.java:665)
        at com.oracle.javafx.scenebuilder.app.SceneBuilderApp.handleOpenFilesAction(SceneBuilderApp.java:510)
        at com.oracle.javafx.scenebuilder.app.welcomedialog.WelcomeDialogWindowController.fireOpenRecentProject(WelcomeDialogWindowController.java:145)
        at com.oracle.javafx.scenebuilder.app.welcomedialog.WelcomeDialogWindowController.lambda$controllerDidLoadFxml$0(WelcomeDialogWindowController.java:126)
        at com.sun.javafx.event.CompositeEventHandler.dispatchBubblingEvent(CompositeEventHandler.java:86)
        at com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:238)
        at com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:191)
        at com.sun.javafx.event.CompositeEventDispatcher.dispatchBubblingEvent(CompositeEventDispatcher.java:59)
        at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:58)
        at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
        at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)
        at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
        at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)
        at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
        at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)
        at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
        at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)
        at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
        at com.sun.javafx.event.EventUtil.fireEventImpl(EventUtil.java:74)
        at com.sun.javafx.event.EventUtil.fireEvent(EventUtil.java:49)
        at javafx.event.Event.fireEvent(Event.java:198)
        at javafx.scene.Node.fireEvent(Node.java:8413)
        at javafx.scene.control.Button.fire(Button.java:185)
        at com.sun.javafx.scene.control.behavior.ButtonBehavior.mouseReleased(ButtonBehavior.java:182)
        at com.sun.javafx.scene.control.skin.BehaviorSkinBase$1.handle(BehaviorSkinBase.java:96)
        at com.sun.javafx.scene.control.skin.BehaviorSkinBase$1.handle(BehaviorSkinBase.java:89)
        at com.sun.javafx.event.CompositeEventHandler$NormalEventHandlerRecord.handleBubblingEvent(CompositeEventHandler.java:218)
        at com.sun.javafx.event.CompositeEventHandler.dispatchBubblingEvent(CompositeEventHandler.java:80)
        at com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:238)
        at com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:191)
        at com.sun.javafx.event.CompositeEventDispatcher.dispatchBubblingEvent(CompositeEventDispatcher.java:59)
        at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:58)
        at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
        at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)
        at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
        at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)
        at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
        at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)
        at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
        at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)
        at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
        at com.sun.javafx.event.EventUtil.fireEventImpl(EventUtil.java:74)
        at com.sun.javafx.event.EventUtil.fireEvent(EventUtil.java:54)
        at javafx.event.Event.fireEvent(Event.java:198)
        at javafx.scene.Scene$MouseHandler.process(Scene.java:3757)
        at javafx.scene.Scene$MouseHandler.access$1500(Scene.java:3485)
        at javafx.scene.Scene.impl_processMouseEvent(Scene.java:1762)
        at javafx.scene.Scene$ScenePeerListener.mouseEvent(Scene.java:2494)
        at com.sun.javafx.tk.quantum.GlassViewEventHandler$MouseEventNotification.run(GlassViewEventHandler.java:381)
        at com.sun.javafx.tk.quantum.GlassViewEventHandler$MouseEventNotification.run(GlassViewEventHandler.java:295)
        at java.security.AccessController.doPrivileged(Native Method)
        at com.sun.javafx.tk.quantum.GlassViewEventHandler.lambda$handleMouseEvent$354(GlassViewEventHandler.java:417)
        at com.sun.javafx.tk.quantum.QuantumToolkit.runWithoutRenderLock(QuantumToolkit.java:389)
        at com.sun.javafx.tk.quantum.GlassViewEventHandler.handleMouseEvent(GlassViewEventHandler.java:416)
        at com.sun.glass.ui.View.handleMouseEvent(View.java:555)
        at com.sun.glass.ui.View.notifyMouse(View.java:937)
        at com.sun.glass.ui.gtk.GtkApplication._runLoop(Native Method)
        at com.sun.glass.ui.gtk.GtkApplication.lambda$null$49(GtkApplication.java:139)
        at java.lang.Thread.run(Thread.java:748)

将SelectableVBox替换为普通的VBox可解决此问题。

预先感谢 滚压

0 个答案:

没有答案