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

Trouble getting out of the blocks  RSS feed

 
Tom O'Malley
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have looked at the archive but could not find an answer. When trying to compile and run the simplist of programs (effectively "Hello World") I was able to compile but not run the program. I get the error Exception in thread "main" java.lang.NoClassDefFoundError: MyFirstApp.
My research informed me that the class def was able to be located during compilation but not at run time. Do I need any special settings?
My environment:
Windows XP Professional
j2sdk1.4.2_03
PATH=C:\j2sdk1.4.2_03\bin
Thank you
 
Michael Morris
Ranch Hand
Posts: 3451
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Tom,
Welcome to JavaRanch. Could you post your code so we can look at it? Be sure to use the CODE tags by pressing the CODE button below and placing your code inside. You may have a problem with your CLASSPATH. For example are you compiling in one directory and trying to run the program from another?
 
Tom O'Malley
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Here is the code...pretty simple stuff. I think you may be right about the CLASSPATH since I didn't set that variable.
 
Michael Morris
Ranch Hand
Posts: 3451
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You shouldn't need to set the CLASSPATH as long as you run it in the same directory that it was compiled. I assume you are using Windows. If so, open a command prompt and navigate to the directory where you compiled the class file. When there type:

If the CLASSPATH is unset it should respond like this:

You should be able to type java MyFirstApp and it should run fine. Also make sure that you do not have a package statement on the first line of the file. If you do, then the class will be stored in a directory according to the package. When learning it is probably best to use the default package, but later, you should always use a package.
 
Tom O'Malley
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Where should the CLASSPATH variable be set to?
 
Tom O'Malley
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Never mind...I got it. I changed the Environment Variable to inlcude a "." at the end (current directory). Thanks for all your help.
 
Michael Morris
Ranch Hand
Posts: 3451
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Tom O'Malley:
Never mind...I got it. I changed the Environment Variable to inlcude a "." at the end (current directory). Thanks for all your help.

You don't need to have the CLASSPATH set for this example to run, but if you do have it set, then having the current directory in there is required.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!