4

此处已就此错误提出了类似的问题,但我已经尝试了大多数解决方案,但仍然收到相同的错误消息。我在我的 java 应用程序中使用 json-simple 库。我在我的库中包含了 json-simple-1.1.1.jar 文件。通过 Netbeans 运行完美。当我尝试通过命令行“java -jar”运行它时,出现以下错误。即使“java -cp json-simple-1.1.1.jar -jar”仍然给出同样的错误。

nullException in thread "AWT-EventQueue-0" java.lang.NoClassDefFoundError: org/json/simple/JSONObject
    at gui.keo_synopticx.jb_save_configMouseClicked(keo_synopticx.java:5318)
    at gui.keo_synopticx.access$6000(keo_synopticx.java:49)
    at gui.keo_synopticx$60.mouseClicked(keo_synopticx.java:3358)
    at java.awt.AWTEventMulticaster.mouseClicked(Unknown Source)
    at java.awt.Component.processMouseEvent(Unknown Source)
    at javax.swing.JComponent.processMouseEvent(Unknown Source)
    at java.awt.Component.processEvent(Unknown Source)
    at java.awt.Container.processEvent(Unknown Source)
    at java.awt.Component.dispatchEventImpl(Unknown Source)
    at java.awt.Container.dispatchEventImpl(Unknown Source)
    at java.awt.Component.dispatchEvent(Unknown Source)
    at java.awt.LightweightDispatcher.retargetMouseEvent(Unknown Source)
    at java.awt.LightweightDispatcher.processMouseEvent(Unknown Source)
    at java.awt.LightweightDispatcher.dispatchEvent(Unknown Source)
    at java.awt.Container.dispatchEventImpl(Unknown Source)
    at java.awt.Window.dispatchEventImpl(Unknown Source)
    at java.awt.Component.dispatchEvent(Unknown Source)
    at java.awt.EventQueue.dispatchEventImpl(Unknown Source)
    at java.awt.EventQueue.access$200(Unknown Source)
    at java.awt.EventQueue$3.run(Unknown Source)
    at java.awt.EventQueue$3.run(Unknown Source)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Source)
    at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Source)
    at java.awt.EventQueue$4.run(Unknown Source)
    at java.awt.EventQueue$4.run(Unknown Source)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Source)
    at java.awt.EventQueue.dispatchEvent(Unknown Source)
    at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
    at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
    at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
    at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
    at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
    at java.awt.EventDispatchThread.run(Unknown Source)
Caused by: java.lang.ClassNotFoundException: org.json.simple.JSONObject
    at java.net.URLClassLoader$1.run(Unknown Source)

我可能缺少 json-simple-1.1.1 的依赖项?任何建议将不胜感激。

4

2 回答 2

1

org/json/simple/JSONObject 类肯定在 jar 文件中。

我能想到的问题的唯一原因是您没有指定jar文件路径,并且该jar与您的执行目录不在同一目录中。

于 2013-03-04T20:49:21.390 回答
0

要解决这个问题,你应该在终端上精确你的类路径:

语法:

java -classpath <your_archive.jar> [<package>.]<Class_name>

如果该类属于某个类,请不要忘记包。

于 2014-09-08T00:59:17.997 回答