Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Error Message

 
Jit Gupta
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 51
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1840
Eclipse IDE Java Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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,
 
Jit Gupta
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1840
Eclipse IDE Java Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you are setting the environment variables, you need to set CLASSPATH (not PATH) to include C:\JIT.
 
Jit Gupta
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic