JavaFX does not allow creating events

-3

First of all, I've researched StackOverFlow on similar posts but did not find it. I'm having a problem with JavaFX because it gives an error every time I try to set any event on whatever component it is (a Button, textArea, etc.).

NOTE: I did not make any changes to the project when I created it, just created it in intelliJ, put a button in Fxml and declared an onClick event (I tried Netbeans too and gave the same error).

OBS2: Before I was not having this error (yesterday was working normally so I do not know what might have happened)

Error:

Exception in Application start method
java.lang.reflect.InvocationTargetException
    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 com.sun.javafx.application.LauncherImpl.launchApplicationWithArgs(LauncherImpl.java:389)
    at com.sun.javafx.application.LauncherImpl.launchApplication(LauncherImpl.java:328)
    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.launcher.LauncherHelper$FXHelper.main(LauncherHelper.java:767)
Caused by: 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$154(LauncherImpl.java:182)
    at java.lang.Thread.run(Thread.java:748)
Caused by: javafx.fxml.LoadException: No controller specified.
/C:/Users/Henrique%20Mauler/Desktop/JavaFXrutaChat/out/production/JavaFXrutaChat/sample/sample.fxml:9

    at javafx.fxml.FXMLLoader.constructLoadException(FXMLLoader.java:2597)
    at javafx.fxml.FXMLLoader.access$100(FXMLLoader.java:103)
    at javafx.fxml.FXMLLoader$Element.getControllerMethodHandle(FXMLLoader.java:557)
    at javafx.fxml.FXMLLoader$Element.processEventHandlerAttributes(FXMLLoader.java:599)
    at javafx.fxml.FXMLLoader$ValueElement.processEndElement(FXMLLoader.java:770)
    at javafx.fxml.FXMLLoader.processEndElement(FXMLLoader.java:2823)
    at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:2532)
    at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:2441)
    at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3214)
    at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3175)
    at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3148)
    at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3124)
    at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3104)
    at javafx.fxml.FXMLLoader.load(FXMLLoader.java:3097)
    at sample.Main.start(Main.java:13)
    at com.sun.javafx.application.LauncherImpl.lambda$launchApplication1$161(LauncherImpl.java:863)
    at com.sun.javafx.application.PlatformImpl.lambda$runAndWait$174(PlatformImpl.java:326)
    at com.sun.javafx.application.PlatformImpl.lambda$null$172(PlatformImpl.java:295)
    at java.security.AccessController.doPrivileged(Native Method)
    at com.sun.javafx.application.PlatformImpl.lambda$runLater$173(PlatformImpl.java:294)
    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$147(WinApplication.java:177)
    ... 1 more
Exception running application sample.Main
    
asked by anonymous 05.01.2019 / 01:09

2 answers

0

Apparently no controller has been defined for your fxml, On line 13

at sample.Main.start(Main.java:13)

and

Caused by: javafx.fxml.LoadException: No controller specified.

To solve this, you should check if your fxml is in the fx: controller tag and inform if there is no

Alternatively, you can tell us about your method:

@Override
public void start(Stage primaryStage) throws Exception{
    FXMLLoader loader = FXMLLoader.load(getClass().getResource("sample.fxml"));
    loader.setController(new Controller());
    Parent root = loader.load();
    primaryStage.setTitle("Hello World");
    primaryStage.setScene(new Scene(root, 300, 275));
    primaryStage.show();
}

Use only one of the two options, the second of which is very useful when you want to inform send parameters to your controller eg:

loader.setController(new Controller(parametro1, parametro2);

Hugs

    
06.01.2019 / 14:19
0

I was able to partially solve the problem. I realized that every time I create a new project. from the moment I determine an event in the SceneBuilder and put the Controller's skeleton in IntelliJ, it works normally. But after I delete the event and the information that is on the Controller, the application stops running. I think there may be some poor implementation in the SceneBuilder software system that keeps some event tag fxml even deleting.

When I determine an event in the SceneBuilder, it is not putting in the tag.

    
06.01.2019 / 17:30