我在我的Minecraft插件中尝试使用JSONObjects时遇到ClassNotFoundException。我已将它添加到我的构建路径(我正在使用IntelliJ),并将其添加为Maven依赖项。我试图谷歌解决方案,但我没有成功因此我决定发帖。
<dependency>
<groupId>org.json</groupId>
<artifactId>json</artifactId>
<version>20160810</version>
<scope>compile</scope>
</dependency>
我试图删除范围,但如果没有它,它也无法工作。 这是我的堆栈跟踪(格式化为代码所以我必须使用pastebin):http://pastebin.com/Q5QVd2S8
StatsCommand 48:
UUID uuid = UUIDFetcher.fetchUUID("arraying");
我的UUIDFetcher fetchUUID方法:
public static UUID fetchUUID(String playerName) {
UUID uuid = null;
try {
JSONObject jsonObject = new JSONObject(IOUtils.toString(new URL("https://api.mojang.com/users/profiles/minecraft/" + playerName), Charsets.UTF_8));
uuid = UUID.fromString(jsonObject.getString("id"));
} catch (Exception e) {
if (!(e instanceof JSONException))
e.printStackTrace();
}
return uuid;
}
我尝试过这个完全相同的代码与另一个项目完全相同的依赖项,并且它在那里工作。我不知道为什么这不起作用。