无法访问类com.sun.javafx.util.Utils(在模块javafx.graphics中)-javafx&;日食

无法访问类com.sun.javafx.util.Utils(在模块javafx.graphics中)-javafx&;日食,java,javafx,scenebuilder,gluon-desktop,Java,Javafx,Scenebuilder,Gluon Desktop,我已经按照这个步骤在Linux机器上安装了JavaFX。 首先,我安装了Java11 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-1ubu

我已经按照这个步骤在Linux机器上安装了JavaFX。 首先,我安装了Java11

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安装了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中创建了一个库

然后我将它包括到我的java项目中。我尝试运行以下代码:

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();
    }

}
我已将运行配置更改为:

--module-path="/usr/share/openjfx/lib" --add-modules=javafx.controls,javafx.fxml

但是当我编译代码时。我发现以下错误:

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
我得到这个错误
与JDK 14的IntelliJ IDEA 2020.1有相同的问题

最后通过在
src/main/java
下添加一个
module info.java
来解决问题,如果您使用maven:

module sample {
    requires javafx.controls;
    requires javafx.graphics;

    opens sample;
}

与JDK 14的IntelliJ IDEA 2020.1有相同的问题

最后通过在
src/main/java
下添加一个
module info.java
来解决问题,如果您使用maven:

module sample {
    requires javafx.controls;
    requires javafx.graphics;

    opens sample;
}

谢谢你,杰克。我照你说的做了,但在那之后我遇到了其他一些例外情况,所以我提出了以下代码:

module {pkg}{
   requires javafx.controls;
   requires javafx.graphics;
   requires javafx.fxml;

   exports {pkg of Application class};

   opens {pkg};
}
之后,您需要重建您的项目,可能是因为Kotlin出现了一些异常。 然后我看到异常“未设置位置”。要解决此问题,必须以“/”开头fxml位置,例如:


编辑


我在使用Gradle时做了一个HelloWorld项目。

谢谢你,伊格纳杰克。我照你说的做了,但在那之后我遇到了其他一些例外情况,所以我提出了以下代码:

module {pkg}{
   requires javafx.controls;
   requires javafx.graphics;
   requires javafx.fxml;

   exports {pkg of Application class};

   opens {pkg};
}
之后,您需要重建您的项目,可能是因为Kotlin出现了一些异常。 然后我看到异常“未设置位置”。要解决此问题,必须以“/”开头fxml位置,例如:


编辑


我在使用Gradle时做了一个HelloWorld项目。

谢谢,我的工作如下

public void start(Stage primaryStage) throws Exception{
        Parent root = FXMLLoader.load(getClass().getResource("sample.fxml"));
module-info.java:

module sample {
    requires javafx.controls;
    requires javafx.graphics;
    requires javafx.fxml;
    opens sample ;
}

谢谢,为我工作如下

public void start(Stage primaryStage) throws Exception{
        Parent root = FXMLLoader.load(getClass().getResource("sample.fxml"));
module-info.java:

module sample {
    requires javafx.controls;
    requires javafx.graphics;
    requires javafx.fxml;
    opens sample ;
}

转到运行>运行配置,然后转到参数选项卡,然后转到VM参数并粘贴以下代码以添加模块 --模块路径/path/to/lib--添加模块javafx.controls,javafx.fxml 请记住将/path/to/lib修改为库的路径
然后单击apply,您就可以设置运行配置,然后单击Arguments选项卡,然后单击VM Arguments并粘贴以下代码以添加模块 --模块路径/path/to/lib--添加模块javafx.controls,javafx.fxml 请记住将/path/to/lib修改为库的路径
然后单击apply,您就可以设置这个问题的副本:@JoséPereda我已经尝试过这个解决方案,但对我来说不起作用。您可能还有其他错误,但您需要在VM参数中包含
javafx.fxml
。@JoséPereda如果我应用
--module path=“/usr/share/openjfx/lib”-add modules=javafx.controls,javafx.fxml
对于我的运行配置,错误会更改。现在我得到了由以下原因引起的
:java.lang.NullPointerException:Location是必需的。
因为它找不到.fxml文件,即使我已经在代码中粘贴了位置。您从未将
src
添加到
getResource()
。。。当它从那里开始精确地查找您的文件时……重复了这个问题:@JoséPereda我尝试了那个解决方案,但对我来说不起作用。您可能有其他错误,但您需要在VM参数中包含
javafx.fxml
。@JoséPereda如果我应用
--module path=“/usr/share/openjfx/lib”--将modules=javafx.controls,javafx.fxml
添加到我的运行配置中,错误会更改。现在我得到了由以下原因引起的
:java.lang.NullPointerException:Location是必需的。
因为它找不到.fxml文件,即使我已经在代码中粘贴了位置。您从未将
src
添加到
getResource()
。。。当它从那里开始精确地查找您的文件时……我们必须在哪里添加此文件?@VasilValchev在src/main/java下(如果您使用maven)。我们必须在哪里添加此文件?@VasilValchev在src/main/java下(如果您使用maven)。