I am using Eclipse IDE 2019-12 and using jre1.8.0_231
I wanted to make a library for an adventure game that was able to read json files to convert them to objects. When I exported the library to a .jar file (not runable) an then imported it into my test project in order to make sure everything worked fine, I made the assets source folder and put in Lantern.json, fillied out what i needed and tried to use my library to convert the json file's values into an Item object and ran the method. However when I ran it I got this error...
Exception in thread "main" java.lang.NoClassDefFoundError: org/json/JSONObject
at com.ferisjumbo.adventure.JSONReader.JSONUtil.getJSONObjectFile(JSONUtil.java:28)
at com.ferisjumbo.adventure.JSONReader.JSONReader.getJSONItem(JSONReader.java:11)
at Main.main(Main.java:7)
Caused by: java.lang.ClassNotFoundException: org.json.JSONObject
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
... 3 more
I have tried researching the error, but to me it sounds like jibberish and doesn't make any sense.
Here are some snippits of whats going on...
//Main (located in src folder in project)
import com.ferisjumbo.adventure.JSONReader.Item;
import com.ferisjumbo.adventure.JSONReader.JSONReader;
public class Main {
public static void main(String[] args) {
Item Lantern = JSONReader.getJSONItem("Lantern.json");
System.out.println(Lantern.toString());
}
}
//JSONReader (located in library)
package com.ferisjumbo.adventure.JSONReader;
import java.util.ArrayList;
import java.util.List;
import org.json.JSONObject;
public class JSONReader {
public static Item getJSONItem(String path) {
JSONObject item = JSONUtil.getJSONObjectFile(path);
.....
//JSONUtil (located in library)
package com.ferisjumbo.adventure.JSONReader;
import java.io.InputStream;
import java.util.Scanner;
import org.json.JSONObject;
public class JSONUtil {
public static String getJSONString(String path) {
Scanner scanner;
InputStream IStream = FileHandler.inputStreamFromFile(path);
scanner = new Scanner(IStream);
String json = scanner.useDelimiter("\\z").next();
scanner.close();
return json;
}
public static JSONObject getJSONObjectFile(String path) {
return new JSONObject(getJSONString(path));
}
Here is the Project tree if you need it
If you need aditional information I can put up more. Thanks!