K
K
Kostya Ivavshchenko2020-10-26 21:39:45
Java
Kostya Ivavshchenko, 2020-10-26 21:39:45

Hello everyone, I'm making a JavaFX application and I can't connect the library, what am I doing wrong?

These are the dependencies I added to pom
5f9717c7afe53472212069.png

Here is the application launcher 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
5f97176da6880831524774.png

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();
Stagestage = new Stage();
stage.setScene(new Scene(root));
stage.showAndWait();
}
});
}
}

And these are the errors thrown by
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)
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. 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 1

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Denis Zagaevsky, 2020-10-28
@mykostyaa

Googled for you
https://stackoverflow.com/a/61405652

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question