简体   繁体   中英

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:

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. 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. These binary files are the bytecode that Java interprets to execute your program. 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. It probably indicates that you haven't set the classpath option when executing your code. This link explains how to set the classpath when you execute

1) Open a new shell and add a new simple program like this.
2) Compile the java code using javac Hello.java
3) Run the code using java Hello
It should work, if you still have issue let know.

在此处输入图片说明

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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