aspose file tools*
The moose likes Beginning Java and the fly likes Trouble with packages! Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Trouble with packages!" Watch "Trouble with packages!" New topic
Author

Trouble with packages!

Stephanie Keeler
Greenhorn

Joined: Jan 04, 2010
Posts: 6
Hi, all, I'm new to the site and to Java, trying to learn by self-study and I could really do with some help! I can't seem to get packages working. I won't go through what I did originally to try to get my code to package, but instead explain that I went through the tutorial found here. I'm working off my laptop, running Windows XP, and what I've done is as follows:

1. Created a directory C:\world
2. Saved the source code into this directory as per instructions
(source code as follows, copied direct from site so as to avoid inexperienced-newbie mistakes)

3. At command line, changed directory until I was at C:\world and typed javac HelloWorld.java. No apparent problems compiling.
4. At command line, still in C:\world, typed java world.HelloWorld as per instructions. The compiler replies as follows:
C:\world>java world.HelloWorld
Exception in thread "main" java.lang.NoClassDefFoundError: world/HelloWorld
Caused by: java.lang.ClassNotFoundException: world.HelloWorld
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClassInternal(Unknown Source)
Could not find the main class: world.HelloWorld. Program will exit.

5. Wondering if this is an operating system thing, try with a slash instead of a dot. Nope.
6. Double-check classpath. Classpath is set to .;..;C:\Program Files\Java\jre1.5.0\lib\ext\QTJava.zip;C:\Documents and Settings\Stephanie\My Documents\JavaDev
7. Add to classpath, so it is now .;..;C:\Program Files\Java\jre1.5.0\lib\ext\QTJava.zip;C:\Documents and Settings\Stephanie\My Documents\JavaDev;C:\world
8. When this doesn't work, despair, followed by posting on this forum.

(as a note, the code I was working on and trying to package included imports, which is what I thought I was doing wrong first.)
Stephanie Keeler
Greenhorn

Joined: Jan 04, 2010
Posts: 6
Just to add to this, I tried 'java HelloWorld' too in the same directory. Didn't work.
Wouter Oet
Saloon Keeper

Joined: Oct 25, 2008
Posts: 2700

Go to your C directory and type java world.Helloworld


"Any fool can write code that a computer can understand. Good programmers write code that humans can understand." --- Martin Fowler
Please correct my English.
Stephanie Keeler
Greenhorn

Joined: Jan 04, 2010
Posts: 6
Boy, do I feel stupid now. Thank you very much!
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

Also, note that "classpath" and "path" are two different things.

"Path" is an OS-level concept and (simplistically) indicates to the shell where it should look for programs to run. The "classpath", by contrast, is a Java-level concept, and (also simplistically) indicates to the JVM where it should look for classes.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Trouble with packages!