Please help me with installing Java

Started by
4 comments, last by Lucky Ace Card 17 years, 9 months ago
Man, I feel like an idiot. I must have installed Java incorrectly. I'm just starting to learn it, so I wrote the HelloWorld.java program. I went into command prompt, did javac HelloWorld.java And it created the class file. However, if I do: java HelloWorld in command prompt, I get this error: Exception in thread "main" java.lang.NoClassDefFoundError: HelloWorld Any help on what I did wrong? Thanks a bunch... I'm learning from some outdated book.
Advertisement
Is the class name EXACTLY the same as the output class name, including the caps of the characters?

Dave
Yes.
HelloWorld
That's it. Caps and all.

*EDIT* Ah, I think I finally got it! I finally managed to figure out how to set my ClassPath.
On a side note: that slightly annoying message can pop up in another situation -- say you have created a moderately large project -- and you use packages. If you navigate to your source folder and compile your code...then try to run the app, it will often fall over with the same message. Reason for this is because packages created by applications (...eclipse, etc) will resolve to a directory structure...so, if you move up a level (cd ..) and try java presentWorkingDirectory/mainclass (or presentWorkingDirectory.mainclass) it will work without a fuss...still, it's a minor issue though it bugged me when it came up :)

Hence why I now create a batch file to run my java programs ;)


~Shiny.
------------'C makes it easy to shoot yourself in the foot. C++ makes it harder, but when you do, it blows away your whole leg.' -Bjarne Stroustrup
Try checking the CLASSPATH environment variable. One of the entries should be '.'
Everyone here is so helpful. Thanks Shiny, I'll remember that for future use. And thanks squashed_bug, I totally forgot about the "." entry. That helps.
Thanks guys.

This topic is closed to new replies.

Advertisement