You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

JNI错误求助:启动Java程序时触发NoClassDefFoundError

启动Java程序出现JNI错误及类找不到问题的解决

错误信息

Error: A JNI error has occurred, please check your installation and try again
Exception in thread "main" java.lang.NoClassDefFoundError: fr/theshark34/swinger/event/SwingerEventListener
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java:756)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
at java.net.URLClassLoader.defineClass(URLClassLoader.java:473)
at java.net.URLClassLoader.access$100(URLClassLoader.java:74)
at java.net.URLClassLoader$1.run(URLClassLoader.java:369)
at java.net.URLClassLoader$1.run(URLClassLoader.java:363)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:362)
at java.lang.ClassLoader.loadClass(ClassLoader.java:418)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:355)
at java.lang.ClassLoader.loadClass(ClassLoader.java:351)
at java.lang.Class.getDeclaredMethods0(Native Method)
at java.lang.Class.privateGetDeclaredMethods(Class.java:2701)
at java.lang.Class.privateGetMethodRecursive(Class.java:3048)
at java.lang.Class.getMethod0(Class.java:3018)
at java.lang.Class.getMethod(Class.java:1784)
at sun.launcher.LauncherHelper.validateMainClass(LauncherHelper.java:650)
at sun.launcher.LauncherHelper.checkAndLoadMain(LauncherHelper.java:632)
Caused by: java.lang.ClassNotFoundException: fr.theshark34.swinger.event.SwingerEventListener
at java.net.URLClassLoader.findClass(URLClassLoader.java:387)
at java.lang.ClassLoader.loadClass(ClassLoader.java:418)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:355)
at java.lang.ClassLoader.loadClass(ClassLoader.java:351)

问题原因

核心是程序运行时找不到Swinger库中的SwingerEventListener类,本质是类路径中缺失Swinger的依赖包——Swinger是一个Java GUI工具库,你的项目依赖它但未正确引入。

解决步骤

  • 检查项目中是否存在Swinger的jar包,没有的话下载对应版本(需匹配项目Java版本)
  • 命令行启动程序时,手动将Swinger jar加入类路径:
    • Windows系统:java -cp "你的主程序.jar;swinger.jar" 你的主类完整路径
    • Linux/macOS系统:java -cp "你的主程序.jar:swinger.jar" 你的主类完整路径
  • IDE环境下(IDEA/Eclipse),在项目依赖管理中添加Swinger jar包;如果用构建工具:
    • Maven(pom.xml)添加依赖:
      <dependency>
          <groupId>fr.theshark34</groupId>
          <artifactId>swinger</artifactId>
          <version>1.8.0</version> <!-- 替换为实际需要的版本 -->
      </dependency>
      
    • Gradle(build.gradle)添加依赖:
      implementation 'fr.theshark34:swinger:1.8.0' // 替换为实际需要的版本
      
  • 若打包成可执行jar,确保打包过程中把Swinger的类一起打包(比如用Maven的shade插件或Gradle的shadow插件)
  • 清理项目中重复的Swinger jar包,避免版本冲突导致加载异常

内容的提问来源于stack exchange,提问作者MIFO 77

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.25 23:54:24