This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes Error Message Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Error Message" Watch "Error Message" New topic

Error Message

Jit Gupta

Joined: Jun 13, 2003
Posts: 26
I am new to Java learning. I have written a simple one line program and compiled it successfully. However, when I want to run the program with java command, error message comes that 'Exception in thread "main" java.lang.NoClassDefFoundError'. I am unable to find the problem. I have installed j2sdk.1.4.2 in my win 98SE machine. I would really appreciate feedback from any of you.
Thanks in advance!
Dorothy Finkel-Laverty
Ranch Hand

Joined: Nov 24, 2001
Posts: 51
Sounds like a classpath error. You can search this forum for the the keyword "classpath", or try this link:
Classpath is an environment variable that tells the JVM where to look for the class files that you have created. You can get around it, but you'll regret any workarounds - it's best to read up on CLASSPATH now and understand it.
[ July 07, 2003: Message edited by: Dorothy Finkel-Laverty ]
Joel McNary

Joined: Aug 20, 2001
Posts: 1817

Typically this error message results from either misspellings or a classpath problem.
1). java -cp . MyMainClass (Substituting MyMainClass for whatever your class name is)
2). Make sure that you have spelled your program's main Class Name correctly (capitalization counts!)
3). If your main class is in a package, make sure that the file structure represents the package structure. If your main class is in the package my.package, be sure that you have the following file structure:
{Current Dir}/my/package/MyMainClass.class
and use:
java -cp . my.package.MyMainClass
as the command line.
If none of these solve the problem, please cut-and-paste and post the error message so that we have a little more information with which to work.

Piscis Babelis est parvus, flavus, et hiridicus, et est probabiliter insolitissima raritas in toto mundo.
Jit Gupta

Joined: Jun 13, 2003
Posts: 26
Thanks for prompt reply. I have set the path in autoexec.bat as
SET PATH=%PATH%;c:\j2sdk1.4.2\bin;C:\JIT
Where JIT is the directory name where I saved It has compiled ok with Javac But when I run java Example, the error messaage comes that Exception in thread "main" java.lang.NoClassDefFoundError:Example
I would appreciate your feedback to correct the problem.
Joel McNary

Joined: Aug 20, 2001
Posts: 1817

If you are setting the environment variables, you need to set CLASSPATH (not PATH) to include C:\JIT.
Jit Gupta

Joined: Jun 13, 2003
Posts: 26
In WIN 98(SE), Autoexec.bat file I have set variables as:
SET PATH=%PATH%;c:\j2sdk1.4.2\bin;
JIT is the directory where I am keeping the file. But things are not working. When I type javac command, message comes that file is not found. However, when I save the same file in root directory, c:\, it works for both javac and java commands.
I would really appreciate your inputs and thanks in advance.
Don't get me started about those stupid light bulbs.
subject: Error Message
Similar Threads
my first java program
Running C++ exe files
Javaw.exe Referenced Memory could not be read.
Exception oin thread "main"
Can't run the Java programs through command prompt or TEXTPAD