Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Getting runtime error on HelloWorld  RSS feed

 
Kelly Gass
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm learning Java from scratch using your website. Followed Javaranch examples verbatim. Downloaded the Sun Java compiler and set up classpath and path variables just like javaranch page. It compiles fine but I get the following error when trying to run the HelloWorld example.

Exception in thread "main" java.lang.NoClassDefFoundError: HelloWorld/class

My PC OS is XP Professional.

I'd appreciate any help, in no hurry, thanks for your time...Kelly
 
Barry Gaunt
Ranch Hand
Posts: 7729
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Are you typing "java HelloWorld" or "java HelloWorld.class"?
 
Kelly Gass
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I've tried both ways. If I don't put the extension on HelloWorld I get:
Exception in thread "main" java.lang.NoClassDefFoundError: HelloWorld
 
Ernest Friedman-Hill
author and iconoclast
Sheriff
Posts: 24217
38
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you've set CLASSPATH to something, mnake sure it includes a dot (.) to represent the current directory; i.e.,

.;whatever;something-else

The best thing to do, actually, is to not set it at all!
 
Jim Yingst
Wanderer
Sheriff
Posts: 18671
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Or you can bypass the CLASSPATH using a command-line switch:

java -cp . HelloWorld

This should work if typed from the same directory that contains HelloWorld.class.
 
Kelly Gass
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes, it worked with the command line switch. That will get me started. Thanks for your quick and helpful response...Kelly
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!