aspose file tools*
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 EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Error Message" Watch "Error Message" New topic
Author

Error Message

Jit Gupta
Greenhorn

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: http://www.coderanch.com/t/386810/java/java/Class-not-found-error
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
Bartender

Joined: Aug 20, 2001
Posts: 1815
Typically this error message results from either misspellings or a classpath problem.
Try:
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.
Thanks,


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

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 Example.java. It has compiled ok with Javac Example.java. 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
Bartender

Joined: Aug 20, 2001
Posts: 1815
If you are setting the environment variables, you need to set CLASSPATH (not PATH) to include C:\JIT.
Jit Gupta
Greenhorn

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;
SET CLASSPATH=c:\JIT
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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Error Message
 
Similar Threads
Javaw.exe Referenced Memory could not be read.
Exception oin thread "main"
Can't run the Java programs through command prompt or TEXTPAD
my first java program
Running C++ exe files