eclipse 线程“main”中的异常 java.lang.NoClassDefFoundError: org/json/JSONObject

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/29226143/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-19 22:30:29  来源:igfitidea点击:

Exception in thread "main" java.lang.NoClassDefFoundError: org/json/JSONObject

javajsoneclipsenoclassdeffounderrorclassnotfoundexception

提问by Nani

I'm using org.json.JSONObjectto pass the parameters to the server. And I'm using Eclipse IDE. I have already added the java-json.jarfile to the build path of the project. but still I'm getting the below exception while running the code and no compilation error is displayed. I did clean the project and refreshed several times but still I end up with exception. is there anything missing?

我正在使用org.json.JSONObject将参数传递给服务器。我正在使用 Eclipse IDE。我已经将java-json.jar文件添加到项目的构建路径中。但是我在运行代码时仍然遇到以下异常,并且没有显示编译错误。我确实清理了项目并刷新了几次,但最终还是出现了异常。有什么遗漏吗?

Exception in thread "main" java.lang.NoClassDefFoundError: org/json/JSONObject
    at java.lang.Class.getDeclaredMethods0(Native Method)
    at java.lang.Class.privateGetDeclaredMethods(Unknown Source)
    at java.lang.Class.getMethod0(Unknown Source)
    at java.lang.Class.getMethod(Unknown Source)
    at sun.launcher.LauncherHelper.validateMainClass(Unknown Source)
    at sun.launcher.LauncherHelper.checkAndLoadMain(Unknown Source)
Caused by: java.lang.ClassNotFoundException: org.json.JSONObject

回答by Anand j. Kadhi

Download the Json jar from hereand add it to the classpath. If its a web application then add its under lib's.

这里下载 Json jar并将其添加到类路径中。如果它是一个 Web 应用程序,则在 lib 下添加它。

回答by iqbal lone

Add maven dependency in pom.xml

在 pom.xml 中添加 maven 依赖

<dependency>
        <groupId>org.json</groupId>
        <artifactId>json</artifactId>
    </dependency>

回答by Nani

I have added the same java-json.jarfile to the Run configuration's class path of the particular java file. And now it's working absolutely fine. thanks everyone!!!

我已将相同的java-json.jar文件添加到特定 java 文件的运行配置的类路径中。现在它工作得很好。谢谢大家!!!