jQuery in Action, 3rd edition
The moose likes Beginning Java and the fly likes Exeption in thread Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Exeption in thread "main" ......." Watch "Exeption in thread "main" ......." New topic

Exeption in thread "main" .......

amit patel
Ranch Hand

Joined: Dec 02, 2001
Posts: 32
Hi there !
Here is the most simple program ever possible in java.
class Q2
public static void main(String[] args)
System.out.println("God man !");

* I set the class path as follow:
PATH --> C:\jdk1.2.2\bin
CLASSPATH --> C:\jdk1.2.2\lib
then when I go to dos-promt and try (to test)
"D:\editplus\mices>javac Q2.java"
it works fine and gives me promt again (it ok so far)
and then I check files in mices folder and Q2.class file is there so the compiling part is over.
the problem comes from here
when I say
"D:\editplus\mices>java Q2"
it gives me this error:
"Exeption in thread "main" java.lang.NoClassDefFound Error: Q2"
I don't know whats went wrong !!! can I compile and run (at promt) from any directory or I have to store my files in some folder for which I set the path???
need help from you guys

[This message has been edited by amit patel (edited December 07, 2001).]
matt hooker
Ranch Hand

Joined: Jul 26, 2001
Posts: 46
Okay Amit. This is a simple problem. You simply need to add a dot '.' (which signifies that java should add the current working directory) to your classpath.
So in your case this would be
Hope this helps.

Its not what you do, its the way you say you've done it.
amit patel
Ranch Hand

Joined: Dec 02, 2001
Posts: 32
G thanks man
I will try that and tell you worked or not...
once again thanks for your help
Marilyn de Queiroz

Joined: Jul 22, 2000
Posts: 9059
PATH is for compiling
CLASSPATH is for running

Unless you are putting your compiled *.class files into C:\jdk1.2.2\lib you don't need that in your classpath. Try including that in your path instead and set your classpath to D:\editplus\mices or whereever your *.class files will be.

The . will work as long as you always type java WhatEverClass while you are in the same directory as the WhatEverClass.class file.
[This message has been edited by Marilyn deQueiroz (edited December 07, 2001).]

"Yesterday is history, tomorrow is a mystery, and today is a gift; that's why they call it the present." Eleanor Roosevelt
amit patel
Ranch Hand

Joined: Dec 02, 2001
Posts: 32
Funny things do happen in computer field.
After long try when I failed in running my java files, I show this on one of the site that J++ builder set the path it self. So I downloaded it and installed it.
Now, I try to run the same file and guess what ? it worked.
bottom line I can compile and run files now.
Thanks for your kind help
subject: Exeption in thread "main" .......
It's not a secret anymore!