1 问题概述

首先是javafx找不到对应的类:



其次是

class com.sun.javafx.fxml.FXMLLoaderHelper (in unnamed module @0x50f36265) 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 @0x50f36265

这种问题。

或者是

Error: JavaFX runtime components are missing, and are required to run this application

这样的问题。

2 解决方案

环境Manjaro+OpenJDK11,首先需要确保有OpenJFX,但是,不能直接使用pacman/yaourt安装:



虽然看上去没什么问题,OpenJDK使用的也是pacman安装的,想着JFX也可以这样,安装之后在

/usr/lib/jvm/java-11-openjdk/lib

下面确实有了JFX的文件,但是装了之后IDEA死活识别不出来,没办法,只能手动安装JFX。

手动安装的OpenJFX一加就马上识别出来了,所以,手动安装吧,也不难,戳这里下载所需要的版本,解压到对应的位置,然后在IDEA中的外部库添加其中的lib文件夹即可:



添加之后另一个问题是

class com.sun.javafx.fxml.FXMLLoaderHelper (in unnamed module @0x50f36265) 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 @0x50f36265

给出的最多的答案是修改VM Options:

--module-path=JFX_LIB_PATH --add-modules=javafx.controls,javafx.fxml

其中JFX_LIB_PATH是JFX下的lib目录路径,但是不行,另一个方案是在源文件目录下添加module-info.java:

module javafx.graphics{
exports com.sun.javafx.util
}

也不行,直接报错,然后又搜索到了另一个解决办法,额外添加一个类似启动类的java文件,比如叫App.java:

import javafx.application.Application;

public class App {
public static void main(String[] args) {
Application.launch(Main.class,args);
}
}

然后修改IDEA的运行配置,把主类修改为App。

这样笔者的问题就解决了,可以正常运行JFX程序了。

3 其他问题

Caused by: java.lang.NullPointerException: Location is required.

其中一个可能的办法是:

Parent root = FXMLLoader.load(getClass().getResource("xxx.fxml"));

改为:

Parent root = FXMLLoader.load(getClass().getClassLoader().getResource("xxx.fxml"));

笔者试过,这个方法不行,另一个解决的方法是,修改pom.xml:

<build>
<resources>
<resource>
<directory>src/main/java</directory>
<includes>
<include>**/*.fxml</include>
</includes>
<filtering>false</filtering>
</resource>
</resources>
</build>

其中include中的两个星号指的是fxml的文件夹的位置。

笔者试过这个方法可行,若fxml文件在源码根目录,可以修改为:

<include>*.fxml</include>

最新文章

  1. (翻译)《Hands-on Node.js》—— Introduction
  2. proc文件系统
  3. mongoDB windows安装
  4. 继承进一步使用,以及super关键字
  5. install zabbix-agent on CENTOS
  6. poj 3635 Full Tank? ( 图上dp )
  7. opencv官网
  8. WebService 的创建,部署和使用
  9. Android中强大的Matrix操作
  10. 帝国cms7.0调用指定栏目,指定顺序排列
  11. 20175333曹雅坤MyCP(课下作业,必做)
  12. CentOS无法使用ifconfig和root密码修改
  13. NET Core 1.1中使用Jwt
  14. 一个smtp发送错误
  15. IDEA导入JUnit4
  16. [C++]Linux之Ubuntu下编译C程序出现错误:“ stray ‘\302&#39;或者&#39;\240&#39; in program”的解决方案
  17. Source Insight 常用设置
  18. template-web.js 引用变量、函数
  19. CSS选择器效率
  20. C/C++ 打开串口和关闭串口

热门文章

  1. springboot项目启动后tomcat服务器自动关闭 解决方法
  2. Redis与Spring Data Redis
  3. vue3中watch函数
  4. c++中深层复制(浅层复制运行错误)成功运行-----sample
  5. HDOJ-2222(AC自动机+求有多少个模板串出现在文本串中)
  6. JQGrid 应用
  7. Celery:小试牛刀
  8. python面试题总结
  9. Hibernate在oracle中ID增长的方式(续)
  10. Windows下的Linux子系统