无法访问类com.sun.javafx.util.Utils(在javafx.graphics模块中)-JavaFX&蚀 [英] Cannot access class com.sun.javafx.util.Utils (in module javafx.graphics) - JavaFX & Eclipse
问题描述
我已遵循此指南将JavaFX设置到Linux机器上. 首先,我已经安装了Java 11
I have follow this guide to setup JavaFX onto a Linux machine. First I have installed Java 11
asus@asus-pc:/usr/share/openjfx/lib$ java -version
openjdk version "11.0.3" 2019-04-16
OpenJDK Runtime Environment (build 11.0.3+7-Ubuntu-1ubuntu219.04.1)
OpenJDK 64-Bit Server VM (build 11.0.3+7-Ubuntu-1ubuntu219.04.1, mixed
mode, sharing)
asus@asus-pc:/usr/share/openjfx/lib$
然后我从命令sudo apt-get install openjfx
asus@asus-pc:/usr/share/openjfx/lib$ ls
javafx.base.jar javafx.graphics.jar javafx.swing.jar
javafx.controls.jar javafx.media.jar javafx.web.jar
javafx.fxml.jar javafx.properties src.zip
asus@asus-pc:/usr/share/openjfx/lib$
然后在Eclipse中创建了一个库.
Then have created a library in Eclipse.
然后将其包含到我的Java项目中.我尝试运行以下代码:
Then I have include it into my java project. I try to run this code:
package se.danielmartensson.start;
import javafx.application.Application;
import javafx.fxml.FXMLLoader;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.stage.Stage;
public class Main extends Application{
/*
* Start the start(Stage front)
*/
public static void main(String[] args) {
launch();
}
@Override
public void start(Stage front) throws Exception {
Parent root = FXMLLoader.load(getClass().getResource("/JUSBPlotter/src/se/danielmartensson/fxml/front.fxml"));
Scene scene = new Scene(root);
front.setScene(scene);
front.setTitle("Fracken");
front.show();
}
}
我将运行配置更改为:
但是当我编译代码时.我收到此错误:
But when I compile the code. I get this errors:
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.IllegalAccessError: class com.sun.javafx.fxml.FXMLLoaderHelper (in unnamed module @0x1ff6d2c7) 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 @0x1ff6d2c7
at com.sun.javafx.fxml.FXMLLoaderHelper.<clinit>(FXMLLoaderHelper.java:38)
at javafx.fxml.FXMLLoader.<clinit>(FXMLLoader.java:2056)
at se.danielmartensson.start.Main.start(Main.java:20)
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.gtk.GtkApplication._runLoop(Native Method)
at javafx.graphics/com.sun.glass.ui.gtk.GtkApplication.lambda$runLoop$11(GtkApplication.java:277)
... 1 more
Exception running application se.danielmartensson.start.Main
问题:
有人知道如何解决此错误吗?我之前已经安装了JavaFX,但是这次对我来说不起作用.
Is there anyone where who know how to solve this error? I have setup JavaFX before, but this time, it won't work for me.
修改1: 如果我将运行配置更改为:
Edit 1: If I change the run configurations to:
--module-path="/usr/share/openjfx/lib" --add-modules=javafx.controls,javafx.fxml
我收到此错误
推荐答案
带有JDK 14的IntelliJ IDEA 2020.1也有同样的问题.
Having the same issue with IntelliJ IDEA 2020.1 with JDK 14.
如果使用maven,则通过在src/main/java
下添加这样的module-info.java
最终解决:
Finally resolved by adding a module-info.java
like this one under src/main/java
if you use maven:
module sample {
requires javafx.controls;
requires javafx.graphics;
opens sample;
}
这篇关于无法访问类com.sun.javafx.util.Utils(在javafx.graphics模块中)-JavaFX&蚀的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!