Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

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

 
amit patel
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Thanks
-=A=-

[This message has been edited by amit patel (edited December 07, 2001).]
 
matt hooker
Ranch Hand
Posts: 46
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
CLASSPATH=C:\jdk1.2.2\lib;.
Hope this helps.
Matt
 
amit patel
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
G thanks man
I will try that and tell you worked or not...
once again thanks for your help
-=A=-
 
Marilyn de Queiroz
Sheriff
Posts: 9065
12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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).]
 
amit patel
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
-=A=-
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic