I have a JavaFX project that I'm working on and seem to have encountered an issue from a Java update. The gui's in the project were built using scene builder and spring is used for dependency injection. I am currently running JavaFX 11 with a Java 11 jre. The project was originally built using Java 8 and JavaFX 2. The loadScreens method shown below is in my main controller class that is responsible for loading all the screens into a hashmap. All the other controller classes then share an instance of this main controller class and can call a setScreen method on any screen in the hashmap and the main controller will set it on the single stage which is also shared by all the controllers.
public void loadScreens() {
for(String screen: screens) {
try {
InputStream fxmlStream = getClass().getResourceAsStream(screen);
FXMLLoader loader = new FXMLLoader();
URL location = getClass().getResource(screen);
loader.setLocation(location);
loader.setControllerFactory(context::getBean);
Object x = loader.load(fxmlStream); // Problem Line
//FXMLLoader loader = new FXMLLoader(getClass().getResource(screen));
//loader.setControllerFactory(context::getBean);
//Scene scene = new Scene(loader.load()); //Problem Line
//scene.setFill(Color.TRANSPARENT);
//addScreen(screen, scene);
}catch(Exception e) {
e.printStackTrace();
}
}
I found what is currently not commented out on the net but it didn't seem to fix the issue. What is commented out is what used to work but now no longer does despite the fact that I havnt touched this class in months. After the java update, it broke. Heres the stack trace
Exception in Application start method
java.lang.reflect.InvocationTargetException
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:566)
at javafx.graphics/com.sun.javafx.application.LauncherImpl.launchApplicationWithArgs(LauncherImpl.java:464)
at javafx.graphics/com.sun.javafx.application.LauncherImpl.launchApplication(LauncherImpl.java:363)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:566)
at java.base/sun.launcher.LauncherHelper$FXHelper.main(LauncherHelper.java:1051)
Caused by: java.lang.RuntimeException: Exception in Application start method
at javafx.graphics/com.sun.javafx.application.LauncherImpl.launchApplication1(LauncherImpl.java:900)
at javafx.graphics/com.sun.javafx.application.LauncherImpl.lambda$launchApplication$2(LauncherImpl.java:195)
at java.base/java.lang.Thread.run(Thread.java:834)
Caused by: java.lang.NoSuchMethodError: sun.reflect.misc.ReflectUtil.newInstance(Ljava/lang/Class;)Ljava/lang/Object;
at javafx.fxml.FXMLLoader$InstanceDeclarationElement.constructValue(FXMLLoader.java:1009)
at javafx.fxml.FXMLLoader$ValueElement.processStartElement(FXMLLoader.java:746)
at javafx.fxml.FXMLLoader.processStartElement(FXMLLoader.java:2707)
at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:2527)
at javafx.fxml.FXMLLoader.load(FXMLLoader.java:2425)
at studentApp.view.ScreenController.loadScreens(ScreenController.java:136)
at studentApp.view.GuiControllerFramework.start(GuiControllerFramework.java:35)
at javafx.graphics/com.sun.javafx.application.LauncherImpl.lambda$launchApplication1$9(LauncherImpl.java:846)
at javafx.graphics/com.sun.javafx.application.PlatformImpl.lambda$runAndWait$12(PlatformImpl.java:455)
at javafx.graphics/com.sun.javafx.application.PlatformImpl.lambda$runLater$10(PlatformImpl.java:428)
at java.base/java.security.AccessController.doPrivileged(Native Method)
at javafx.graphics/com.sun.javafx.application.PlatformImpl.lambda$runLater$11(PlatformImpl.java:427)
at javafx.graphics/com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:96)
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)
... 1 more
Exception running application studentApp.view.GuiControllerFramework
I thought that maybe because the FXMLLoader class returns an Object for the no arg .load() method that it was saying that there was no such method because it was an Object. So I added the "Object x" line second, but first tried casting the object to Scene, which doesn't work because there is no matching constructor in the scene class and I tried casting it to type Parent which didn't stop the error from occuring. Originally, as can be seen in the commented out code, I just passed the no arg load method into the scene constructor and everything worked fine. Now since adding this standalone javaFX 11 my code doesn't work anymore. I don't exactly want to go back to javaFX 2 but have been stuck on this for days. If I use my original, now commented out code, and comment out the load line and the two below it, it compiles fine though I get a blank scene. As can be seen I am using springs application context for the bean definitions. If anyone has any ideas I'd greatly appreciate it. Thanks guys.