简体   繁体   English

线程“ main”中的异常java.lang.NoClassDefFoundError:org / javatuples / Unit

[英]Exception in thread “main” java.lang.NoClassDefFoundError: org/javatuples/Unit

I have imported the javatuples-1.2.jar in Eclipse project. 我已经在Eclipse项目中导入了javatuples-1.2.jar。 I did this to run the Java Tuples Unit class program. 我这样做是为了运行Java Tuples Unit类程序。 The following is the code: 以下是代码:

 package mynewpackage;
 import org.javatuples.Unit; 

 class Mynewclass2 { 
  public static void main(String[] args) 
   { 
    Unit<String> u 
        = new Unit<String>("This is demo text!"); 

    System.out.println(u); 
   } 
 } 

But, getting the following error on running: 但是,在运行时出现以下错误:

Exception in thread "main" java.lang.NoClassDefFoundError: org/javatuples/Unit
    at mynewpackage.Mynewclass2.main(Mynewclass2.java:9)
Caused by: java.lang.ClassNotFoundException: org.javatuples.Unit
    at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:583)
    at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:178)
    at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:521)
    ... 1 more

Under the references, I can easily see that the tuples jar file is successfully added. 在引用下,我可以轻松地看到已成功添加了元组jar文件。 However, the following is the project directory, jar in references, error, and the entire program in Eclipse. 但是,以下是项目目录,引用中的jar,错误以及Eclipse中的整个程序。

带有Java元组的Eclipse项目目录

How can I fix the issue and run Java Tuples programs correctly? 如何解决该问题并正确运行Java Tuples程序?

Right Click on javatuples-1.2.jar > Build path > Add to Build Path . 右键单击javatuples-1.2.jar>构建路径>添加到构建路径。

NoClassDefFoundError is an error that is thrown when the Java Runtime System tries to load the definition of a class, and that class definition is no longer available. NoClassDefFoundError是Java运行时系统尝试加载类的定义时抛出的错误,并且该类定义不再可用。

Comments are Welcome. 欢迎发表评论。

You have java 11 in place... 您已经安装了Java 11 ...

When I (try to) reproduce your setup: 当我(尝试)重现您的设置时:

  1. My eclipse (Version: 2018-12 (4.10.0), Win_64_jdk_11.0.2) asks me for "module name" and adds src/module-info.java after creation of a "Java Project", ... then download and add lib/javatuples-1.2.jar to build path. 我的日食(版本:2018-12(4.10.0),Win_64_jdk_11.0.2)要求我提供“模块名称”,并在创建“ Java项目”后添加src/module-info.java ,然后下载并添加lib/javatuples-1.2.jar构建路径。

  2. When I try to use/import it in my code (main class) - compilation error, and auto-correct proposes me to add "javatuples" module to module-info: 当我尝试在代码(主类)中使用/导入它时-编译错误,并且自动更正建议我向模块信息中添加“ javatuples”模块:

click-clack: 点击率:

myproject/src/module-info.java myproject / src / module-info.java

module myproject {
   requires javatuples;
}

After that the program is already runnable, but Eclipse warns : 之后,该程序已经可以运行,但是Eclipse警告

Name of automatic module 'javatuples' is unstable, it is derived from the module's file name.

To fix this, you can run (from command line): 解决此问题,可以运行(从命令行):

myproject>jar --file=lib/javatuples-1.2.jar --describe-module
No module descriptor found. Derived automatic module.

javatuples@1.2 automatic
requires java.base mandated
contains org.javatuples
contains org.javatuples.valueintf

So, eclipse warning is already sort of nasty: javatuples is the "correct" module name. 因此,日食警告已经有点麻烦了: javatuples是“正确的”模块名称。

Hope it helps. 希望能帮助到你。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 “线程”main“中的异常 java.lang.NoClassDefFoundError: org/hamcrest/SelfDescribing” - “Exception in thread ”main“ java.lang.NoClassDefFoundError: org/hamcrest/SelfDescribing” 线程“main”中的异常java.lang.NoClassDefFoundError:org / reactivestreams / Publisher? - Exception in thread “main” java.lang.NoClassDefFoundError: org/reactivestreams/Publisher? 线程“main”中的异常 java.lang.NoClassDefFoundError: org/jsoup/Jsoup - Exception in thread "main" java.lang.NoClassDefFoundError: org/jsoup/Jsoup 线程“ main”中的异常java.lang.NoClassDefFoundError:org / mockito / Mockito - Exception in thread “main” java.lang.NoClassDefFoundError: org/mockito/Mockito 线程“main”中的异常java.lang.NoClassDefFoundError:org / json / JSONObject - Exception in thread “main” java.lang.NoClassDefFoundError: org/json/JSONObject 线程“main”中的异常 java.lang.NoClassDefFoundError: org/hamcrest/Matchers - Exception in thread "main" java.lang.NoClassDefFoundError: org/hamcrest/Matchers 主线程java.lang.NoClassDefFoundError中的异常 - Exception in main thread java.lang.NoClassDefFoundError 线程“ main”中的异常java.lang.NoClassDefFoundError - exception in thread 'main' java.lang.NoClassDefFoundError 线程“main”java.lang.NoClassDefFoundError中的异常: - Exception in thread “main” java.lang.NoClassDefFoundError: 线程“主”java.lang.NoClassDefFoundError 中的异常: - exception in thread 'main' java.lang.NoClassDefFoundError:
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM