Hello everyone, I'm making an application in JavaFX and can't connect the library, what am I doing wrong?
-
These are the dependencies I added to the pom
Here is the application launch class
import javafx.application.Application;
import javafx.fxml.FXMLLoader;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.stage.Stage;
import java.io.IOException;
public class App extends Application {
private Stage primaryStage;
public static void main (String [] args) {
launch (args);
}
@Override
public void start (Stage primaryStage) throws IOException {
this.primaryStage = primaryStage;
showMainView ();
}
private void showMainView () throws IOException {
FXMLLoader loader = new FXMLLoader ();
loader.setLocation (getClass (). getResource ("resources / NewGame.fxml"));
Parent mainLayout = loader.load ();
Scene scene = new Scene (mainLayout);
primaryStage.setScene (scene);
primaryStage.show ();
}
}
Here is the JavaFX file
Here is the controller class
package controllers;
import java.io.IOException;
import java.net.URL;
import java.util.ResourceBundle;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.fxml.FXML;
import javafx.fxml.FXMLLoader;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.stage.Stage;
public class NewGameController {
@FXML
private ResourceBundle resources;
@FXML
private URL location;
@FXML
private Button NewGameButton;
@FXML
private Button MainExit;
@FXML
void initialize () {
NewGameButton.setOnAction (new EventHandler () {
public void handle (ActionEvent event) {
NewGameButton.getScene (). GetWindow (). Hide ();
FXMLLoader loader = new FXMLLoader ();
loader.setLocation (NewGameController.this.getClass (). getResource ("/ resources / SettingGame"));
try {
loader.load ();
} catch (IOException e) {
e.printStackTrace ();
}
Parent root = loader.getRoot ();
Stage stage = new Stage ();
stage.setScene (new Scene (root));
stage.showAndWait ();
}
});
}
}
And these are the errors it gives.
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:567)
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:567)
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:830)
Caused by: java.lang.IllegalAccessError: class com.sun.javafx.fxml.FXMLLoaderHelper (in unnamed module @ 0x458439e3) cannot access class com.sun.javafx.util.Utils (in module javafx.graphics) because module javafx.graphics does not export com.sun.javafx.util to unnamed module @ 0x458439e3
at com.sun.javafx.fxml.FXMLLoaderHelper. (FXMLLoaderHelper.java:38)
at javafx.fxml.FXMLLoader. (FXMLLoader.java:2056)
at App.showMainView (App.java:25)
at App.start (App.java:22)
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 (AccessController.java:391)
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 App
Process finished with exit code 1Java Parker Sullivan, Nov 18, 2020
1 Answers
Your Answer
To place the code, please use CodePen or similar tool. Thanks you!