• Post Reply Bookmark Topic Watch Topic
  • New Topic

Classpath error  RSS feed

 
Dan Crowther
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Like many people I see here, I too am working with the Head First Java book.

I'm also getting the "Exception in Thread "main" java.lang.noclassdeffounderror: MyFirstApp"

From what I been able find it looks like it's related to paths. The paths I currently have are:

c:\program files\java\jdk1.5.0_06\bin; w:\java projects;

The first is where java and javac are located and the second is where I'm building the projects. Do I need another path to somewhere else?

Thanks!
 
Keith Lynn
Ranch Hand
Posts: 2409
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You need to keep the distinction between the PATH and CLASSPATH in mind. The CLASSPATH has nothing to do with finding java and javac. You would put the directory containing java.exe and javac.exe in your PATH. The CLASSPATH contains a list of directories that will be searched to find .class files. If you don't have a CLASSPATH set, then the current directory is your CLASSPATH. If you do have a CLASSPATH set, but the current directory is not in it, then the interpreter will not see your .class file even though it's in your current directory.
 
Dan Crowther
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Good, I didn't realize the distinction.

By sound of your reply classpath needs to be set to the place where the *.class files are being created after I run a *.java file through the compiler? ("w:\java projects" in my case)

Now, how do I set classpath?
[ February 22, 2006: Message edited by: Dan Crowther ]
 
Keith Lynn
Ranch Hand
Posts: 2409
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In Windows XP, you can go to Control Panel, System, Advanced, Environment Variables and set it.
 
Keith Lynn
Ranch Hand
Posts: 2409
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can also override the System CLASSPATH, if on the command line you include -cp when you call the interpreter.

java -cp . classname
 
Dan Crowther
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Excellent! Thank you, cruising right along now.

Thanks
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!