java.lang.ClassNotFoundException: org.json.simple.parser.JSONParser

994 Views Asked by At

I have included json-simple in my pom.xml for Maven:

<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: Screenie

1

There are 1 best solutions below

1
GregGott On

I don't mean the module manager of IntelliJ.

If you add modules to your project you need a modular project. Such a project needs a class called module-info.java.

According to the openjfx documentation:

Add the module-info class, including the required modules javafx.controls and javafx.fxml. Since FXML uses reflection to access the controller in the module, this has to be opened to javafx.fxml. Finally, export the package org.openjfx.

See image

In your case the module-info.java file should look similar to this (maybe some differences):

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.