1

When looking at the JavaFX SceneBuilder, it is able to load any kind of fxml. The root node or controller are disregarded. The scenebuilder is able to load any kind of fxml and can display its components.

Does anybody fancy a way to load a fxml diregarding its field's id's, controller or type of root node?

The problem is, when I try to load any fxml, it can only load, if I set the correct root type. I want to load (via FileChooser) any FXML I can find into (lets say) a pane.

Any ideas would be appreciated (all help in www directs to loading mechanisms which use a specific root type, so the root type is known). I want to load unknown root types disregarding fx:id's etc.

The exception:

Exception in Application start method
Exception in thread "main" java.lang.RuntimeException: Exception in Application start method
    at com.sun.javafx.application.LauncherImpl.launchApplication1(LauncherImpl.java:917)
    at com.sun.javafx.application.LauncherImpl.lambda$launchApplication$152(LauncherImpl.java:182)
    at com.sun.javafx.application.LauncherImpl$$Lambda$2/1531448569.run(Unknown Source)
    at java.lang.Thread.run(Thread.java:745)
Caused by: java.lang.RuntimeException: javafx.fxml.LoadException: 
/C:/Users/Dominik/Documents/fhnw/bath/svn/examples/fxmlloader/out/production/FxHeatMap/eu/hansolo/fx/heatmap/fxmlload/Application.fxml:20

    at eu.hansolo.fx.heatmap.fxmlload.FXMLLoader.start(FXMLLoader.java:34)
    at com.sun.javafx.application.LauncherImpl.lambda$launchApplication1$159(LauncherImpl.java:863)
    at com.sun.javafx.application.LauncherImpl$$Lambda$66/84373524.run(Unknown Source)
    at com.sun.javafx.application.PlatformImpl.lambda$runAndWait$172(PlatformImpl.java:326)
    at com.sun.javafx.application.PlatformImpl$$Lambda$47/1537074899.run(Unknown Source)
    at com.sun.javafx.application.PlatformImpl.lambda$null$170(PlatformImpl.java:295)
    at com.sun.javafx.application.PlatformImpl$$Lambda$50/1947223685.run(Unknown Source)
    at java.security.AccessController.doPrivileged(Native Method)
    at com.sun.javafx.application.PlatformImpl.lambda$runLater$171(PlatformImpl.java:294)
    at com.sun.javafx.application.PlatformImpl$$Lambda$48/835743810.run(Unknown Source)
    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$145(WinApplication.java:101)
    at com.sun.glass.ui.win.WinApplication$$Lambda$38/1962582134.run(Unknown Source)
    ... 1 more
Caused by: javafx.fxml.LoadException: 
/C:/Users/Dominik/Documents/fhnw/bath/svn/examples/fxmlloader/out/production/FxHeatMap/eu/hansolo/fx/heatmap/fxmlload/Application.fxml:20

    at javafx.fxml.FXMLLoader.constructLoadException(FXMLLoader.java:2605)
    at javafx.fxml.FXMLLoader.access$700(FXMLLoader.java:104)
    at javafx.fxml.FXMLLoader$ValueElement.processAttribute(FXMLLoader.java:918)
    at javafx.fxml.FXMLLoader$InstanceDeclarationElement.processAttribute(FXMLLoader.java:967)
    at javafx.fxml.FXMLLoader$Element.processStartElement(FXMLLoader.java:216)
    at javafx.fxml.FXMLLoader$ValueElement.processStartElement(FXMLLoader.java:740)
    at javafx.fxml.FXMLLoader.processStartElement(FXMLLoader.java:2711)
    at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:2531)
    at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:2445)
    at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3218)
    at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3179)
    at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3152)
    at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3128)
    at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3108)
    at javafx.fxml.FXMLLoader.load(FXMLLoader.java:3101)
    at eu.hansolo.fx.heatmap.fxmlload.FXMLLoader.start(FXMLLoader.java:32)
    ... 14 more
Caused by: java.lang.ClassNotFoundException: sample.MainController
    at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
    at javafx.fxml.FXMLLoader$ValueElement.processAttribute(FXMLLoader.java:916)
    ... 27 more

Process finished with exit code 1
Uluk Biy
  • 48,655
  • 13
  • 146
  • 153
mambax
  • 1,079
  • 8
  • 17

1 Answers1

0

There are fx:controller and fx:root attributes. Don't be confused. You can disregard the root layout type by casting the loaded object to the Parent super class. But I think there is no way to disregard fx:controller defined in fxml file. What you need in this case, is to load the file yourself and remove the fx:controller with its value from the file.

Uluk Biy
  • 48,655
  • 13
  • 146
  • 153
  • Thank you in first place for your inputs, I thought that could be the case. If I look at Gluon OSS spcifically at the class FXMOLoader they somehow manage to load any FXML. But cheees this would let my project 'frame' explode :( – mambax Jun 08 '15 at 09:52
  • @m4mbax, ScenBuilder is open source and you can read its code from bitbucket. If I could have some time I could look the code where the arbitrary fxml files are loaded, and see how it is managed there. But you can try it. – Uluk Biy Jun 08 '15 at 10:03
  • Yes I also intend to do that :) Thank you anyway for your help, f I succeed somehow I will post it here :) – mambax Jun 08 '15 at 11:03
  • I (repectively my project advisor) found out something new, but am stuck with a deprectated method: See here --> https://gist.github.com/cfdeb2ed0313946c8624, do you have any uptodate ideas why this method is deprecated and what its non-deprecated follower could be? – mambax Jun 11 '15 at 18:23
  • @m4mbax, it seems `staticLoad` and some other variables in FXMLLoader code are used for SceneBuilder only. So they are not meant to be used in regular API usage, and thus they have `impl_` prefix and annotated as deprecated. These methods should be treated as private (for internal usage) and can be changed without providing compatibility on future releases of JavaFX. There is no non-deprecated alternatives for them. Being said that, I think you may continue to use them for the next few years. I also think they will not be changed in a short period of time. – Uluk Biy Jun 12 '15 at 06:00