Open gluon-bot opened 7 years ago
Original comment by A. Walter (Bitbucket: awalterwork, GitHub: Unknown):
Updated issue title to reflect that this is not about ClassNotFoundExceptions (anymore).
Original comment by A. Walter (Bitbucket: awalterwork, GitHub: Unknown):
Update:
Thanks to https://bugs.openjdk.java.net/browse/JDK-8122760 , I figured out that the custom controls should set the class loader for the FXML loaders they create in their constructors. I did so by adding "loader.setClassLoader(this.getClass().getClassLoader());" to their constructors right after the FXML loaders were created.
This indeed fixed the ClassNotFoundExceptions when loading the resulting JAR. (I committed the updated code and the resulting JAR in the repository linked in the question.)
However, it is still not possible to open the FXML file that uses the nested custom controls because of a new LoadException, going back to a ClassCastException in this case, based in SceneBuilder code:
#!java
java.io.IOException: javafx.fxml.LoadException:
path/to/proj/src/nestedCustomControlsFxml/OutermostFxml.fxml:19
at com.oracle.javafx.scenebuilder.kit.fxom.FXOMLoader.load(FXOMLoader.java:92)
at com.oracle.javafx.scenebuilder.kit.fxom.FXOMDocument.<init>(FXOMDocument.java:82)
at com.oracle.javafx.scenebuilder.kit.fxom.FXOMDocument.<init>(FXOMDocument.java:97)
at com.oracle.javafx.scenebuilder.kit.editor.EditorController.updateFxomDocument(EditorController.java:2384)
at com.oracle.javafx.scenebuilder.kit.editor.EditorController.setFxmlTextAndLocation(EditorController.java:664)
at com.oracle.javafx.scenebuilder.app.DocumentWindowController.loadFromFile(DocumentWindowController.java:385)
at com.oracle.javafx.scenebuilder.app.SceneBuilderApp.performOpenFiles(SceneBuilderApp.java:634)
at com.oracle.javafx.scenebuilder.app.SceneBuilderApp.performOpenFile(SceneBuilderApp.java:580)
at com.oracle.javafx.scenebuilder.app.SceneBuilderApp.performControlAction(SceneBuilderApp.java:209)
at com.oracle.javafx.scenebuilder.app.menubar.MenuBarController$ApplicationControlActionController.perform(MenuBarController.java:1675)
at com.oracle.javafx.scenebuilder.app.menubar.MenuBarController.handleOnActionMenu(MenuBarController.java:1119)
at com.oracle.javafx.scenebuilder.app.menubar.MenuBarController.lambda$new$3(MenuBarController.java:1113)
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.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:58)
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.control.MenuItem.fire(MenuItem.java:462)
at com.sun.javafx.scene.control.skin.ContextMenuContent$MenuItemContainer.doSelect(ContextMenuContent.java:1405)
at com.sun.javafx.scene.control.skin.ContextMenuContent$MenuItemContainer.lambda$createChildren$343(ContextMenuContent.java:1358)
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.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:380)
at com.sun.javafx.tk.quantum.GlassViewEventHandler$MouseEventNotification.run(GlassViewEventHandler.java:294)
at java.security.AccessController.doPrivileged(Native Method)
at com.sun.javafx.tk.quantum.GlassViewEventHandler.lambda$handleMouseEvent$354(GlassViewEventHandler.java:416)
at com.sun.javafx.tk.quantum.QuantumToolkit.runWithoutRenderLock(QuantumToolkit.java:389)
at com.sun.javafx.tk.quantum.GlassViewEventHandler.handleMouseEvent(GlassViewEventHandler.java:415)
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:745)
Caused by: javafx.fxml.LoadException:
path/to/proj/src/nestedCustomControlsFxml/OutermostFxml.fxml:19
at javafx.fxml.FXMLLoader.constructLoadException(FXMLLoader.java:2601)
at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:2579)
at javafx.fxml.FXMLLoader.load(FXMLLoader.java:2425)
at com.oracle.javafx.scenebuilder.kit.fxom.FXOMLoader.load(FXOMLoader.java:89)
... 53 more
Caused by: java.lang.ClassCastException: com.oracle.javafx.scenebuilder.kit.fxom.TransientProperty cannot be cast to com.oracle.javafx.scenebuilder.kit.fxom.TransientObject
at com.oracle.javafx.scenebuilder.kit.fxom.FXOMLoader.endElement(FXOMLoader.java:315)
at javafx.fxml.FXMLLoader.processEndElement(FXMLLoader.java:2826)
at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:2532)
... 55 more
OutermostFxml.fxml is:
#!xml
<?xml version="1.0" encoding="UTF-8"?>
<?import javafx.geometry.Insets?>
<?import javafx.scene.control.Button?>
<?import javafx.scene.control.Label?>
<?import javafx.scene.layout.BorderPane?>
<?import javafx.scene.layout.HBox?>
<?import javafx.scene.layout.VBox?>
<?import java.lang.*?>
<?import nestedCustomControlsFxml.*?>
<?import javafx.collections.*?>
<OuterCustomControl fx:id="Including" prefHeight="1080.0" prefWidth="1920.0"
xmlns="http://javafx.com/javafx/8.0.101" xmlns:fx="http://javafx.com/fxml/1">
<innerCustomControl>
<toolbarContent>
<Button text="Test from Outermost Fxml"></Button>
</toolbarContent> <!-- this is line 19 -->
</innerCustomControl>
</OuterCustomControl>
Line 19 is indicated by the LoadException , which is where a tag defined by InnerCustomControl is closed.
As OutermostFxml.fxml can be successfully loaded and displayed by a JavaFx application and the class loader issue was corrected, this indeed appears to be a SceneBuilder problem.
Hi folks, any progress on this issue?
I don't think this is the exact issue you were having, but if it helps anyone else, when I made my java package names start with a capital letter this started happening to me. Changing them to be lowercase fixed the issue. Eg i had: main/FXML/Views/CustomView.java but i had to change it to: main/fxml/views/CustomView.java
Originally reported by: A. Walter (Bitbucket: awalterwork, GitHub: Unknown)
Hello,
I've encountered a problem with SceneBuilder 8.3.0 and nested custom components that is similar, but NOT identical, to Issue #60 .
Description
Custom control OuterCustomControl that contains another custom control InnerCustomControl is not correctly imported into SceneBuilder because of a ClassNotFoundException for InnerCustomControl when OuterCustomControl's FXML OuterCustomControl.fxml is loaded in OuterCustomControl's constructor. However, SceneBuilder CAN load OuterCustomControl.fxml directly without any problems.
As a consequence, FXMLs that reference controller properties of custom control OuterCustomControl can not be opened by SceneBuilder. However, those FXMLs can be loaded and displayed in pure JavaFx code without any problems.
Setup to reproduce/demonstrate
see a sample repo that demonstrates the issue .
a custom control InnerCustomControl that loads InnerCustomControl.fxml in its constructor.
a custom control OuterCustomControl that loads OuterCustomControl.fxml in its constructor. The FXML references InnerCustomControl.
an FXML OutermostFxml.fxml that references OuterCustomControl (extends it and references controller properties of OuterCustomControl).
App.java demonstrates that OutermostFxml.fxml can be loaded/displayed in JavaFx code.
a JAR containing the custom controls.
Steps
Open SceneBuilder (preferably from a terminal so we can see log messages etc.).
Import the JAR containing the custom controls. Both custom controls (InnerCustomControl and OuterCustomControl) show up in the Import dialog and can be imported, no errors or warnings are shown. [This is where this bug is different from Issue #60, in which custom controls did not show up at all.] The JAR Analysis Report is empty. However in the terminal, we can see exceptions caused by a ClassNotFoundException for InnerCustomControl when OuterCustomControl's constructor tries to load OuterCustomControl.fxml:
Try to directly open OuterCustomControl.fxml: This works as expected without any problems.
Try to open OutermostFxml.fxml which references OuterCustomControl: This fails with an error message indicating the first line where we try to access properties of OuterCustomControl's controller:
Try to load OutermostFxml.fxml in Java (using App.java): This works as expected without any problems.
Summary
Actual behaviour: The nested custom control InnerCustomControl is not found during SceneBuilder's loading process for OuterCustomControl (when OuterCustomControl.fxml is loaded from OuterCustomControl's controller), but it IS found if we directly open/load OuterCustomControl.fxml.
Expected behaviour: The nested custom control should be found during SceneBuilder's loading process for OuterCustomControl.
Actual behaviour: A LoadException occurs if we open OutermostFxml.fxml in SceneBuilder, but there is no such exception if the same file is loaded in a JavaFx application.
Expected behaviour: There should be no LoadException, SceneBuilder should be able to open OutermostFxml.fxml.
Thanks in advance!
A. Walter