[CLUE-Tech] NoClassDefFoundError

Jeffery Cann fabian at jefferycann.com
Thu Jun 12 20:13:44 MDT 2003


Joseph,

We discussed this last week in my reply about your classes being compiled in a 
package and your command line does not reference the package.  Perhaps you 
didn't see the list reply?  Check the archives at:

 + http://clue.denver.co.us/pipermail/clue-tech/

In this case, your IDE (or you) put your HelloWorld class in the 'test' 
package.  Since you don't reference this package on the command line, the JVM 
cannot find the class.  This is why the error says 'wrong name: 
test/HelloWorld:

[phierce at localhost test]$ java HelloWorld
Exception in thread "main" java.lang.NoClassDefFoundError: HelloWorld (wrong 
name: test/HelloWorld)
--------^^^^^^^^^^^^^^

You need to:

[phierce at localhost test]$ java test/HelloWorld


Please read up on the Java package concept:

+ http://java.sun.com/docs/books/tutorial/java/interpack/packages.html

Regards,
Jeff

On Thursday 12 June 2003 06:39 pm, Joseph Thomas wrote:
> Hello all,
>
> ok I had java running on my red hat linux fine, but recently I am unable to
> run my java programs through the terminal, but I am able to run them in my
> IDE (eclipse)
>
> Here is the code ( a simple hello world ):
>
> public class HelloWorld {
>
>    public static void main(String args[]){
>       System.out.println("Hello World!");
>    }
>
> }
>
>
> And here is the error I am getting:
>
> [phierce at localhost test]$ java HelloWorld
> Exception in thread "main" java.lang.NoClassDefFoundError: HelloWorld
> (wrong name: test/HelloWorld)
>         at java.lang.ClassLoader.defineClass0(Native Method)
>         at java.lang.ClassLoader.defineClass(ClassLoader.java:488)
>         at
> java.security.SecureClassLoader.defineClass(SecureClassLoader.java:106)
>         at java.net.URLClassLoader.defineClass(URLClassLoader.java:243)
>         at java.net.URLClassLoader.access$100(URLClassLoader.java:51)
>         at java.net.URLClassLoader$1.run(URLClassLoader.java:190)
>         at java.security.AccessController.doPrivileged(Native Method)
>         at java.net.URLClassLoader.findClass(URLClassLoader.java:183)
>         at java.lang.ClassLoader.loadClass(ClassLoader.java:294)
>         at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:281)
>         at java.lang.ClassLoader.loadClass(ClassLoader.java:250)
>         at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:310)
>
> [phierce at localhost test]$ java test.HelloWorld
> Exception in thread "main" java.lang.NoClassDefFoundError: test/HelloWorld
>
> Any ideas on what causes this? Again I only recieve these errors when ran
> in a terminal window, but not in my IDE. I get this on ANY java program I
> try.
>
> Thanks!
>
> _________________________________________________________________
> The new MSN 8: advanced junk mail protection and 2 months FREE*
> http://join.msn.com/?page=features/junkmail
>
> _______________________________________________
> CLUE-Tech mailing list
> Post messages to: CLUE-Tech at clue.denver.co.us
> Unsubscribe or manage your options:
> http://clue.denver.co.us/mailman/listinfo/clue-tech

-- 
"Keep yourselves far from every form of exaggerated nationalism, racism and 
intolerance."
-- Pope John Paul II 



More information about the clue-tech mailing list