我正在尝试将 JSON Simple 导入到我正在使用 Eclipse 开发的 java 项目中。
我的问题是,无论我做什么,在调用使用 JSON Simple 的类时都会收到此错误:
“线程中的异常”AWT-EventQueue-0“java.lang.NoClassDefFoundError:org/json/simple/JSONObject”
但是,我确实通过转到项目属性/Java 构建路径/库/添加外部 JAR 来添加库
我遇到的所有教程仅此而已,而且有效......
我尝试移动 jar 文件,但无论它是在项目根目录的 lib 文件夹中还是在桌面上,它都不会改变任何内容。
import org.json.simple.JSONObject;
import org.json.simple.*;
public class JSONSimple {
@SuppressWarnings("unchecked")
public static void writePlayers(Player[] players){
JSONObject obj = new JSONObject();
JSONArray playerList = new JSONArray();
JSONObject player;
JSONArray scoreList;
for(int i = 0; i < players.length; i++) {
player = new JSONObject();
player.put("pseudo", players[i].getPseudo());
scoreList = new JSONArray();
for(int j = 0; j < players[i].getNextLevelToPass()-1; j++) {
scoreList.add(players[j].getLevelScore(j));
}
player.put("scoreList", scoreList);
player.put("nextLevelToPass", players[i].getNextLevelToPass());
playerList.add(player);
}
obj.put("playerTab", playerList);
System.out.println(obj);
}
}
最佳答案
好的,经过一些测试,当您位于“Java Build Path/Libraries”中时,您需要在“Classpath”而不是“Modulepath”中导入外部库。我这样做了,现在可以了。
关于java - 如何在 Eclipse 中导入 JSON Simple?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61621474/