-1

Working on a project and when I switched my code over to the main branch I started to get some errors. one of them being the Load Exception error. The whole log also shows off a No such method exception error.

WARNING: Loading FXML document with JavaFX API of version 9 by JavaFX runtime of version 8.0.141
java.lang.NoSuchMethodException: corendon.controllers.StatisticsOverviewController.<init>(corendon.View)
    at java.lang.Class.getConstructor0(Class.java:3082)
    at java.lang.Class.getConstructor(Class.java:1825)
    at corendon.View.lambda$fxmlFileLoader$0(View.java:41)
    at javafx.fxml.FXMLLoader$ValueElement.processAttribute(FXMLLoader.java:929)
    at javafx.fxml.FXMLLoader$InstanceDeclarationElement.processAttribute(FXMLLoader.java:971)
    at javafx.fxml.FXMLLoader$Element.processStartElement(FXMLLoader.java:220)
    at javafx.fxml.FXMLLoader$ValueElement.processStartElement(FXMLLoader.java:744)
    at javafx.fxml.FXMLLoader.processStartElement(FXMLLoader.java:2707)
    at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:2527)
    at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:2441)
    at javafx.fxml.FXMLLoader.load(FXMLLoader.java:2409)
    at corendon.View.fxmlFileLoader(View.java:51)
    at corendon.View.load(View.java:30)
    at corendon.controllers.DashboardController.handleStatisticsButtonAction(DashboardController.java:70)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at sun.reflect.misc.Trampoline.invoke(MethodUtil.java:71)
    at sun.reflect.GeneratedMethodAccessor1.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at sun.reflect.misc.MethodUtil.invoke(MethodUtil.java:275)
    at javafx.fxml.FXMLLoader$MethodHandler.invoke(FXMLLoader.java:1769)
    at javafx.fxml.FXMLLoader$ControllerMethodEventHandler.handle(FXMLLoader.java:1657)
    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.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.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.win.WinApplication._runLoop(Native Method)
    at com.sun.glass.ui.win.WinApplication.lambda$null$148(WinApplication.java:191)
    at java.lang.Thread.run(Thread.java:748)
javafx.fxml.LoadException: No controller specified.
/C:/Users/*****/Documents/NetBeansProjects/fasten-your-seatbelts-master/target/classes/views/statistics/overview.fxml:18

I've made sure that the controller is set correctly in the FXML file where the top level settings are

<VBox xmlns="http://javafx.com/javafx/8.0.141" xmlns:fx="http://javafx.com/fxml/1" fx:controller="corendon.controllers.StatisticsOverviewController">

The error points to line 18 of the code which states a fxml menuitem.

15   <children>
16      <MenuButton fx:id="MenuButton" mnemonicParsing="false" text="Select">
17         <items>
18            <MenuItem fx:id="Stats3Days" mnemonicParsing="false" onAction="#Stats3Days" text="Statistics for the last 3 days" />
19            <MenuItem fx:id="Stats21Days" mnemonicParsing="false" onAction="#Stats21Days" text="Statistics for the last 21 days" />
20            <MenuItem fx:id="StatsAllTime" mnemonicParsing="false" onAction="#StatsAllTime" text="Statistics all time" />
21         </items>
22      </MenuButton>

I'd like to post the controller as well but since it's over 600 lines long I'm not really sure if that'd be helpful, I've made sure that every method inside of the controller is public, the only privates that are there are the variables and the Charts I use.

Dapal Lioda
  • 1
  • 1
  • 2
  • 1
    That looks as though the build hasn't worked properly. Can you check that the FXML file that is being used at runtime is the correct version (the full path is referenced in the last line of the stack trace)? Perhaps post the constructor(s) for the controller class and the code that loads the FXML: looks like you are using a controller factory on the FXML loader, so include that. – James_D Jan 14 '18 at 14:27
  • Going through the path confirmed that the fxml file is the same I see in my IDE, I got quite a few constructors so I won't be able to post them all in this comment. Here's a pastebin link. https://pastebin.com/9KbanRd1 It also contains, what I think to be, the fxml loader. I've not coded it myself as this is part of a team task. And for the last part I've tried googling what a controller factory is but I'm not quite sure still on what it is. – Dapal Lioda Jan 14 '18 at 14:48
  • Don't post links to code. Can you at least verify that the constructor it is trying to call is there (the one taking a `View` parameter?). If you didn't write this code and don't understand it, there's probably little anyone here can do to help. Wouldn't it be easier just to ask other members of your team? – James_D Jan 14 '18 at 14:52
  • Anyway, that's not actually what I asked. Check the FXML at the location that appears in the stack trace, and make sure the code in that file is the same as the code in your source directory; i.e. make sure the FXML file was correctly deployed. – James_D Jan 14 '18 at 14:54
  • I've asked them, and neither do they know what the problem. I didn't know that I couldn't do that, sorry. Checking the file from the source directory and comparing it directly to the fxml file from the error shows that they're the exact same file. – Dapal Lioda Jan 14 '18 at 15:04
  • OK, so is the constructor that it's trying to invoke present in the controller? – James_D Jan 14 '18 at 15:06
  • No it wasn't, that was quite an oversight on my side. Adding it in allowed the code to run without any errors. Thanks for helping me out here, really appreciate it. – Dapal Lioda Jan 14 '18 at 15:18

2 Answers2

0

From the stack trace, the error is occurring when an event handler is invoked on DashboardController (the handler method is handleStatisticsButtonAction). That method invokes a method load() in the View class, which in turn invokes fxmlFileLoader() in the same class, which loads the overview.fxml file via an FXMLLoader.

The exception says that the loader is looking for a constructor in StatisticsOverviewController taking a single parameter of type View, and trying to invoke it by reflection. It seems this constructor doesn't exist. So the fix is either to add that constructor or to modify the code that is causing the FXMLLoader to look for that constructor.

Presumably (you didn't post any of the relevant code, so I can only make educated guesses here), since the FXMLLoader is trying to instantiate a controller class from a constructor other than the default constructor, you must be setting a controller factory on the FXMLLoader. It looks like this is implemented with a lambda expression at and around line 41 of View. My guess (again) is that if an exception is encountered in the controller factory, the controller factory prints the stack trace and returns null.

Consequently, when you try to load overview.fxml, you see the stack trace caused by the NosuchMethodException, and the FXMLLoader proceeds to load the FXML with a null controller. The first time it encounters a handler method in the FXML file, which is at the MenuItem in line 18, it fails because there is no controller to map that handler method to.

So, again, the fix is either to provide the correct controller constructor in StatisticsOverviewController, or to change the logic of the controller factory in the View class. Which you do depends on exactly what you are trying to achieve when you load this FXML file.

James_D
  • 201,275
  • 16
  • 291
  • 322
0

I ran into this issue for more than a week and tried variety of suggestions on the web. However, the solution came like this.

  1. If you have your controller in different package, specify your controller as "yourPackageName.yourControllerName". This will solve the issue.

Using "/" did not work for me.