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 Servlets and the fly likes what is exception in thread 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 » Servlets
Bookmark "what is exception in thread "main"" Watch "what is exception in thread "main"" New topic

what is exception in thread "main"

Annette L'Heureux
Ranch Hand

Joined: Dec 07, 2000
Posts: 135
I think I have accidently changed some settings or something, because everything I try to run from a command prompt gives me the error
"exception in thread "main": java.lang.NoClassDefFoundError"
What could be the cause of this? I've doubled checked my classpath and my path.
Thomas Paul
mister krabs
Ranch Hand

Joined: May 05, 2000
Posts: 13974
If you get that error it means you are trying to run a class that does not have a main() method using the "java" command. To run a servlet you need to use "ServletRunner" not "java".

Associate Instructor - Hofstra University
Amazon Top 750 reviewer - Blog - Unresolved References - Book Review Blog
Bosun Bello
Ranch Hand

Joined: Nov 06, 2000
Posts: 1510
You mentioned that you have checked your path. The java interpreter is case sensitive. Make sure you are typing in your class name correctly. That's usually the most likely cause for teh JVM not finding the class file your are specifying.

So much trouble in the world -- Bob Marley
Annette L'Heureux
Ranch Hand

Joined: Dec 07, 2000
Posts: 135
sorry, I don't think it's any of those reasons....
When I first started learning java, I had the "Sam's teach yourself java2 in 21 days" and in it there is a series of exercises you can do. I must have done around 30-40 of them, all of which compiled and ran successfully. Now when I go back to them and try and run them, I get that error. The spelling is all right, and I'm not necessarily trying to run servlets. Even a simple hello world application isn't running.
Maybe it's because it's friday and I'm tired!!! I'm sure I'm just overlooking something.
Thanks for all your help,
Thomas Paul
mister krabs
Ranch Hand

Joined: May 05, 2000
Posts: 13974
are you typing "java Class1.class" . You have to leave off the .class and jus type "java Class1"
Anuj Anand
Ranch Hand

Joined: Nov 18, 2000
Posts: 96
Yes Annette have a nice weekend and come back to Java not before Sunday
Brett Knapik
Ranch Hand

Joined: Oct 15, 2000
Posts: 255
i used to get this error and it was my class path...but you checked that..can't help you.
I wish there was a button on my monitor to turn up the intellegince.
Theres a button called 'brightness' but it doesn't work

"Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning."
mohit joshi
Ranch Hand

Joined: Sep 23, 2000
Posts: 243
This classpath business on NT is more tricky then on 95/98. It may not suffice to keep it in the autoexec file, some times it is required that you put it in the classpath Environment variable in the Environment properties of System ( from Control Panel).
in any case, the actual classpath can be checked by typing
echo %classpath% on the console
Hope it helps
Sheldon Rego

Joined: Nov 03, 2000
Posts: 12
Hey try adding .; in your classpath as well as the path as that will make it the compiler in the present directory as well.
Annette L'Heureux
Ranch Hand

Joined: Dec 07, 2000
Posts: 135
thanks for all the suggestions!
It seems I was able to fix the problem by completely uninstalling the jdk and reinstalling it. Now everywith works fine! That's good for a monday morning! (Now if only the 25cm of snow they are forcasting for tonight will just not come!!!).
thanks again!
I agree. Here's the link:
subject: what is exception in thread "main"
Similar Threads
An exception
why thread priority is not working here
Error Message
static inner class