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
Exception in thread "main" java.lang.NoClassDefFoundError: org/json/JSONObject
提问by Nani
I'm using org.json.JSONObject
to pass the parameters to the server. And I'm using Eclipse IDE. I have already added the java-json.jar
file 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
回答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.jar
file 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 文件的运行配置的类路径中。现在它工作得很好。谢谢大家!!!