简体   繁体   English

java.lang.NoClassDefFoundError:和其他错误

[英]java.lang.NoClassDefFoundError: and other error

I have created a file java named "cancelladir" that is in a directory name "cancelladir", when I write, in my ubuntu shell, "javac cancelladir.java" It create a cancelladir.class but when I try to execute the file java with the command "java cancelladir " there are some error like this: 我在目录名“ cancelladir”中创建了一个名为“ cancelladir”的文件java,当我在ubuntu外壳中编写“ javac cancelladir.java”时,它会创建一个cancelladir.class,但是当我尝试执行文件java时使用命令“ java cancelladir”,会出现如下错误:

Exception in thread "main" java.lang.NoClassDefFoundError: cancelladir (wrong name: cancelladir/cancelladir)
    at java.lang.ClassLoader.defineClass1(Native Method)
    at java.lang.ClassLoader.defineClass(ClassLoader.java:800)
    at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
    at java.net.URLClassLoader.defineClass(URLClassLoader.java:449)
    at java.net.URLClassLoader.access$100(URLClassLoader.java:71)
    at java.net.URLClassLoader$1.run(URLClassLoader.java:361)
    at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:425)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:358)
    at sun.launcher.LauncherHelper.checkAndLoadMain(LauncherHelper.java:482)

I have already set the classpath at export CLASSPATH=.:/home/lisa/graphhopper/graphhopperAndrea/web/src/main/webapp/cancelladir and try to recompile but nothing change. 我已经在export CLASSPATH=.:/home/lisa/graphhopper/graphhopperAndrea/web/src/main/webapp/cancelladir设置了类路径,并尝试重新编译,但没有任何变化。 What is the problem?? 问题是什么?? what I have to do? 我该怎么办?

After you compile your code, you end up with .class files for each class in your program. 编译代码后,最终会得到程序中每个类的.class文件。 These binary files are the bytecode that Java interprets to execute your program. 这些二进制文件是Java解释为执行程序的字节码。 The NoClassDefFoundError indicates that the classloader, which is responsible for dynamically loading classes, cannot find the .class file for the class that you're trying to use. NoClassDefFoundError指示负责动态加载类的类加载器找不到您要使用的类的.class文件。 It probably indicates that you haven't set the classpath option when executing your code. 它可能表明您在执行代码时未设置classpath选项。 This link explains how to set the classpath when you execute 该链接说明了执行时如何设置类路径

1) Open a new shell and add a new simple program like this. 1)打开一个新的外壳并添加一个新的简单程序,如下所示。
2) Compile the java code using javac Hello.java 2)使用javac Hello.java编译Java代码
3) Run the code using java Hello 3)使用Java Hello运行代码
It should work, if you still have issue let know. 如果您仍有问题,请联系我们。

在此处输入图片说明

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM