[英]java.lang.ClassNotFoundException: org.json.simple.parser.JSONParser
I have included json-simple in my pom.xml for Maven:我在 Maven 的 pom.xml 中包含了 json-simple:
<dependencies>
<dependency>
<groupId>com.googlecode.json-simple</groupId>
<artifactId>json-simple</artifactId>
<version>1.1.1</version>
</dependency>
</dependencies>
And I keep getting this error:我不断收到这个错误:
Caused by: java.lang.ClassNotFoundException: org.json.simple.parser.JSONParser
at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:641)
at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:188)
at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:520)
... 3 more
Here is my code:这是我的代码:
JSONObject testLatest = new JSONObject(Files.readString(Paths.get("test-latest.json")));
JSONObject currentServer = new JSONObject(Files.readString(Paths.get("current-server.json")));
String latestStability = testLatest.getJSONObject("response").getString("stability");
String latestMD5 = testLatest.getJSONObject("response").getString("md5");
String currentMD5 = currentServer.getJSONObject("response").getString("md5");
if (latestStability.equals("stable") && !latestMD5.equals(currentMD5)) {
replaceCurrentServer(true);
return true;
}
Here is a screenshot of my module settings in InteliJ:这是我在 InteliJ 中的模块设置的屏幕截图:
I don't mean the module manager of IntelliJ.我不是指 IntelliJ 的模块管理器。
If you add modules to your project you need a modular project .如果您将模块添加到您的项目中,您需要一个模块化项目。 Such a project needs a class called module-info.java
.这样的项目需要一个名为module-info.java
的类。
According to the openjfx documentation :根据openjfx 文档:
Add the
module-info
class, including the required modulesjavafx.controls
andjavafx.fxml
.添加module-info
类,包括所需的模块javafx.controls
和javafx.fxml
。 Since FXML uses reflection to access the controller in the module, this has to be opened tojavafx.fxml
.由于 FXML 使用反射来访问模块中的控制器,因此必须将其打开到javafx.fxml
。 Finally, export the packageorg.openjfx
.最后,导出包org.openjfx
。
In your case the module-info.java
file should look similar to this (maybe some differences) :在您的情况下, module-info.java
文件应该与此类似(可能存在一些差异) :
module com.example.project {
requires javafx.controls;
requires javafx.fxml;
requires json.simple;
requires javafx.graphics;
opens com.example.project to javafx.fxml;
exports com.example.project;
}
After that, your code should work.之后,您的代码应该可以工作。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.