Logo 
Search:

Java Forum

Ask Question   UnAnswered
Home » Forum » Java       RSS Feeds

exception in thread "main" java.lang.NoClassDefFoundError

  Asked By: Trupti    Date: Dec 13    Category: Java    Views: 1487
  

I could not get my first program working.

class HelloDan {
public static void main(String[] arguments) {
System.out.println("What's the frequency, Kenneth?");
}
}

When I type on dos mode. c:\javac hellodan.java I don't see any
error but when I run it c:\java hellodan

I get an error Exception in thread "main"
java.lang.NoClassFefFoundError. I am using window 2000. I have
classpath c:\j2sdk1.4.1_02\lib\tools.jar;
path c:\j2sdk1.4.1_02\bin;

Can someone tell me what went wrong? I need help to get it going.

Sometime I make a new one and run javac. Sometime I don't see any
*.class files. I use search file and could not find it. Why does
this happen?

Share: 

 

6 Answers Found

 
Answer #1    Answered By: Mae Roberts     Answered On: Dec 13

It is case sensitive.
"java HelloDan" not "java hellodan"

Include the '.'(current) directory in your classpath.

 
Answer #2    Answered By: Freda Lane     Answered On: Dec 13

Make sure the directory where the classes it needs are
in the classpath also. So if you are in the current
directory where your file is in then add the following
to your java  command.

-cp %CLASSPATH%;.

 
Answer #3    Answered By: Hooriya Khan     Answered On: Dec 13

Can you use the following 2 commands :

javac HelloDan.java
java HelloDan

 
Answer #4    Answered By: Adalia Fischer     Answered On: Dec 13

I did that. When I run javac  hellodan.java. I don't see any errors.
When I run java  hellodan and got an errors.

I copy from dos  mode.

c:\java progrtam>javac hellodan.java

c:\java program>java hellodan
Exception in thread  "main" java.lang.NoClassDefFoundError: hellodan
<wrong name: hellodan>

at java.long.ClassLoader.defineClass0(Native Method)
at java.long.ClassLoader.defineClass(ClassLoader.java:502)Native Method)
at java.security.SecureClassLoader.defineClass
(SecureClassLoader.java:123)
at java.net.URLClassLoader.defineClass(URLClassLoader.java:250)
at java.net.URLClassLoader.access$100(URLClassLoader.java:54)
at java.net.URLClassLoader$1.run(URLClassLoader.java:193)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:186)
at java.lang.ClassLoader.loadClass(ClassLoader.java:299)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:265)
at Java.lang.ClassLoader.loadClass(ClassLoader.java:255)
at.java.lang.ClassLoader.loadClassInternal(ClassLoader.java:315)

c:\java Program>


 
Answer #5    Answered By: Tracy Myers     Answered On: Dec 13


try

java -cp %CLASSPATH%;

 
Answer #6    Answered By: Corbin Jones     Answered On: Dec 13

set JAVA_HOME=c:\j2sdk1.4.1_02
set PATH=%JAVA_HOME%\bin;%PATH%
set CLASSPATH=. (Root directory of your CLASSES, or path to your JAR FILE)

java MyApplication

If you do not know the usage/purpose of "classpath" please read it up on
java.sun.com or your favourite java  book.

 
Didn't find what you were looking for? Find more on exception in thread "main" java.lang.NoClassDefFoundError Or get search suggestion and latest updates.