2

Possible Duplicates:
Exception in thread “main” java.lang.NoClassDefFoundError: DiServer <wrong name: ds/DiServer>
java.lang.NoClassDefFoundError when i run java file from terminal

I have a program with multiple classes and compile them on the terminal with javac *.java and then try to run the main file by simple doing java filename but it spits out the following error. I don't know what it wants. Help will be appreciated.

Exception in thread "main" java.lang.NoClassDefFoundError: lab6 (wrong name: lab6/lab6)
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClassCond(ClassLoader.java:632)
at java.lang.ClassLoader.defineClass(ClassLoader.java:616)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:141)
at java.net.URLClassLoader.defineClass(URLClassLoader.java:283)
at java.net.URLClassLoader.access$000(URLClassLoader.java:58)
at java.net.URLClassLoader$1.run(URLClassLoader.java:197)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
at java.lang.ClassLoader.loadClass(ClassLoader.java:307)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
at java.lang.ClassLoader.loadClass(ClassLoader.java:248)
Community
  • 1
  • 1
dawnoflife
  • 1,572
  • 10
  • 42
  • 62
  • 3
    Please use the search before asking new questions. Many things have already been answered on SO and you may get your answer instantly. – Brian Roach Apr 18 '11 at 07:08

1 Answers1

7

The error message means that you tried to execute your class using java lab6, but it's actually called lab6.lab6 (i.e. it's in a package called lab6 and its simple name is lab6).

To execute it, you point your classpath to the directory containing the directory lab6 and execute java lab6.lab6.

The easiest way is to go into that directory (whatever it is called) and execute java -cp . lab6.lab6.

Joachim Sauer
  • 302,674
  • 57
  • 556
  • 614