Results 1 to 13 of 13
- 09-25-2008, 06:34 AM #1
Exception in thread "main" java.lang.NoClassDefFoundError
Hi,
>>Demo.java
public class Demo
{
public static void main(String args[])
{
System.out.println("Hello...");
}
}
> javac Demo.java
compilied successfuly and class file got generated.
> java Demo
Then i am getting
"Exception in thread "main" java.lang.NoClassDefFoundError".
I set java/bin folder in path variable.
Could you tell me why am i getting this error and how can I solve this?
- 09-25-2008, 06:49 AM #2
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,370
- Blog Entries
- 1
- Rep Power
- 25
After the compilation check that Demo.class file is created or not in the same location of your source file is located.
Did you working on any Java IDE?
- 09-25-2008, 06:53 AM #3
No, I am not working on IDE. I have checked for class file. Its is there in current directory. But i am not able to run it.
- 09-25-2008, 07:06 AM #4
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,370
- Blog Entries
- 1
- Rep Power
- 25
Other than that in the code there is no any issue also, so it must run well. Just type javac and see what happen on the command prompt, I hope you are working on Windows platform.
- 09-25-2008, 07:56 AM #5
Yes, I am working on Windows Vista. I compiled it, but I didnt get any error.
When I use 'javap', it is showing the content properly.
- 09-25-2008, 09:10 AM #6
Senior Member
- Join Date
- Jun 2008
- Posts
- 2,568
- Rep Power
- 14
If you are in the same directory as your class file (and it does not have a package) then you need to include "." (current directory) on your classpath
Java Code:java -cp . Demo
- 09-25-2008, 11:14 AM #7
Member
- Join Date
- Sep 2008
- Posts
- 17
- Rep Power
- 0
IN Environment variable CLASSPATH add (.) means current working directory
like this
your_prev_path;.;
RegardsSagar Birari
Development & Technical Blog
- 09-25-2008, 05:11 PM #8
Here's what I get when I execute the java command with a non existant class file:
D:\JavaDevelopment\Testing>dir asdf
Volume in drive D is Work
Volume Serial Number is 1463-F5AE
Directory of D:\JavaDevelopment\Testing
File Not Found
D:\JavaDevelopment\Testing>java asdf
Exception in thread "main" java.lang.NoClassDefFoundError: asdf
Can you try executing the dir command followed by java command then copy and paste the output here?
- 09-26-2008, 04:15 AM #9
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,370
- Blog Entries
- 1
- Rep Power
- 25
Anyway that class file is missing in the location he/she run the code. As far as I know that's the only situation where NoClassDefFoundError come across.
- 09-26-2008, 01:24 PM #10
Member
- Join Date
- Sep 2008
- Posts
- 1
- Rep Power
- 0
HI...
WHEN JVM CANNOT ABLE TO FIND THE .class file . THEN WE WILL GET THIS ERROR .."Exception in thread "main" java.lang.NoClassDefFoundError".SO WHILE EXECUTING i mean to say drive_name java class file name...checkout drive name or folder name...etc
- 09-26-2008, 04:29 PM #11
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,370
- Blog Entries
- 1
- Rep Power
- 25
In compilation *.class file is created in the same file *.java file located. Unless you change the working folder on the command prompt after compilation, it don't effect to this exception anyway.
- 06-06-2012, 09:51 AM #12
Member
- Join Date
- Jun 2012
- Posts
- 1
- Rep Power
- 0
Re: Exception in thread "main" java.lang.NoClassDefFoundError
Hi ,
what is mentioned by masijade is working fine ie. java -cp . filename
is working in command propmt of windows. This is because my .java and .class files are in the same directory.
Thanks and Regards,
Manish Gupta
- 06-06-2012, 10:04 AM #13
Moderator
- Join Date
- Feb 2009
- Location
- New Zealand
- Posts
- 4,716
- Rep Power
- 17
Similar Threads
-
Exception in thread "main" java.lang.NoClassDefFoundError: welcome
By MadDogMullan in forum New To JavaReplies: 8Last Post: 09-18-2008, 01:55 PM -
Exception in thread "main" java.lang.NoClassDefFoundError: client Help
By b000m in forum New To JavaReplies: 6Last Post: 08-18-2008, 07:44 AM -
ERROR: Exception in thread "main" java.lang.NoSuchMethodError: main
By barney in forum New To JavaReplies: 1Last Post: 08-07-2007, 08:10 AM -
Exception in thread "main" java.lang.NoClassDefFoundError
By baltimore in forum New To JavaReplies: 1Last Post: 08-06-2007, 07:07 AM -
Exception in thread "main" java.lang.NoClassDefFoundError
By carl in forum New To JavaReplies: 2Last Post: 08-01-2007, 06:26 AM
Bookmarks