• Post Reply Bookmark Topic Watch Topic
  • New Topic

Problem with JDK  RSS feed

 
Ranch Hand
Posts: 431
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Friends

I have installed jdk1.4 in my system. I am able to compile and create .class files, but when i try to run them it shows an error saying

Error in thread "main" in FileName.java :NoClassDefFoundError.

If I install the same jdk in some other machine it works fine. But in my machine I am not able to run anything. Is it a problem due to OS / Hardware configuration. Please help me out as soon as possible. Thanx.

Regards
S.L.Narayanan
 
Ranch Hand
Posts: 410
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Are you trying to run an applet or an application? The error message indicating that it can't find the main method in your class. This could be because:

1) You don't have a main method at all (there must be a method that starts:

with the exact same case.

2) You are trying to run an applet, which are executed in a different way to applications. Let me know if this is the case and you need assistance.
 
Ranch Hand
Posts: 236
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
My guess is that maybe you had been running on a Unix machine (which is case-sensitive), and you're now on a DOS/Windows machine (where the OS
isn't case sensitive ... but Java is).

Please do the following:

1. Double check the name of the class with your "main()" method:
EXAMPLE: "class MyClass {"

2. Make sure your file is spelled *exactly* the same way:
EXAMPLE: "MyClass.java"

2a) If you're typing in your program from a Windows command
prompt, be advised that "notepad" has a nasty habit of
changing your filename behind your back:
EXAMPLE: Did "File, Save as" to "MyClass.java"
But got file "MyClass.java.txt".

The solution is to choose file type "All files(*.*)" before
you save (or simply rename the file after you save).

3. Do a test compile. It should work:
EXAMPLE: javac MyClass.java

4. Try running again. If "main()" is in the module, is declared
"public static void main (String[] args)", and if the module
compiles ... then you *should* be home free.

'Hope that helps .. PSM
[ May 11, 2005: Message edited by: Paul Santa Maria ]
 
S.L.Narayanan
Ranch Hand
Posts: 431
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Friends

My class has the "main" method correctly. I am able to compile the file and create the .class file but when I try to run (it is a application only, not applet) it is showing the error.

I have installed the same in my friend's machine and done the same thing, there I am able to run the application. I dont know why it is not working in my system. Mine is windows only.
 
Ranch Hand
Posts: 5093
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sounds like the traditional problem of not having the current directory ('.') in the classpath.
Somewhat sad that someone who is SCJP doesn't know that :roll:
 
S.L.Narayanan
Ranch Hand
Posts: 431
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
couldnt understand what u r telling...I had set the classpath correctly...but can u tell me what shud be the value of the classpath?
 
S.L.Narayanan
Ranch Hand
Posts: 431
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
one more thing...if i didnt set the classpath correctly then i shud not be able to compile u know...it cannot detect the javac.exe first of all...but that is working fine...when i run like java ClassName it is showing the error which i mentioned above....
 
Ranch Hand
Posts: 1683
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Do not confuse the PATH (needed to locate javac.exe) and the CLASSPATH (needed to locate the .class files).
 
S.L.Narayanan
Ranch Hand
Posts: 431
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ok..Tell me what shud be the value of the CLASSPATH?...
 
Roger Chung-Wee
Ranch Hand
Posts: 1683
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you have your .class files in, say, C:\app\classes, then ensure that C:\app\classes is on your classpath. If you have archived your files in a JAR file, then the JAR file itself must be on your classpath.
 
Ranch Hand
Posts: 1228
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Add this "." ( dot ) in class path.

like CLASSPATH = %CLASSPATH%;.;
( This is for windows )
 
S.L.Narayanan
Ranch Hand
Posts: 431
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ok...Thanx...I will try this out (if already not there) and tell u tomorrow...
 
S.L.Narayanan
Ranch Hand
Posts: 431
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ok...Thanx...I will try this out (if already not there) and tell u tomorrow...
 
Don't get me started about those stupid light bulbs.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!