Exception in thread "main" java.lang.noclassdef............

Thread Solved

Join Date: May 2009
Posts: 9
Reputation: sgsawant is an unknown quantity at this point 
Solved Threads: 0
sgsawant's Avatar
sgsawant sgsawant is offline Offline
Newbie Poster

Exception in thread "main" java.lang.noclassdef............

 
0
  #1
May 25th, 2009
When I tried to compile my HelloWorldApp.java file using the following command:
javac HelloWorldApp.java
it worked (for being able to do this simple thing I had to change a lot of variables).

But then when I tried to Run the program using:
java HelloWorldApp
it gave me the error:
Exception in thread "main" java.lang.noclassdef


To solve this error I tried various commands like:
set classpath=%classpath%;.;
java -classpath . HelloWorldApp
java -classpath . HelloWorldApp.class

but to no avail. Can anyone help me out with this problem?

Regards,

-sgsawant
Last edited by sgsawant; May 25th, 2009 at 3:08 am.
Reply With Quote Quick reply to this message  
Join Date: Nov 2008
Posts: 823
Reputation: verruckt24 is a jewel in the rough verruckt24 is a jewel in the rough verruckt24 is a jewel in the rough verruckt24 is a jewel in the rough 
Solved Threads: 73
verruckt24's Avatar
verruckt24 verruckt24 is offline Offline
Practically a Posting Shark

Re: Exception in thread "main" java.lang.noclassdef............

 
0
  #2
May 25th, 2009
While compiling you need to specify the .java file, you are right on that part, but while running the file through the java command you cannot specify the .java file, such a file won't simply run, the JVM would need a .class file. So you would have to execute the command in this way :
javac HelloWorldApp the class loader would look for a file with that name and a .class extension.
Get up every morning and take a look at the Forbes' list of richest people. If your name doesn't appear.... GET TO WORK !!!
Reply With Quote Quick reply to this message  
Join Date: May 2009
Posts: 9
Reputation: sgsawant is an unknown quantity at this point 
Solved Threads: 0
sgsawant's Avatar
sgsawant sgsawant is offline Offline
Newbie Poster

Re: Exception in thread "main" java.lang.noclassdef............

 
0
  #3
May 25th, 2009
Originally Posted by verruckt24 View Post
While compiling you need to specify the .java file, you are right on that part, but while running the file through the java command you cannot specify the .java file, such a file won't simply run, the JVM would need a .class file. So you would have to execute the command in this way :
javac HelloWorldApp the class loader would look for a file with that name and a .class extension.
My sincerest apologies. As you have rightly pointed out it will not run if I command "java HelloWorldApp.java" but I also tried "java HelloWorldApp". I have also corrected the entry in the original post.

The error still persists. In fact if I had typed "java HelloWorldApp.java" it would have given me a different error.


Can you find the mistake I am making?

Regards,

-sgsawant
Reply With Quote Quick reply to this message  
Join Date: Jun 2006
Posts: 7,609
Reputation: ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of 
Solved Threads: 464
Super Moderator
Featured Poster
~s.o.s~'s Avatar
~s.o.s~ ~s.o.s~ is offline Offline
Failure as a human

Re: Exception in thread "main" java.lang.noclassdef............

 
0
  #4
May 25th, 2009
> So you would have to execute the command in this way :
> javac HelloWorldApp the class loader would look for a file with that
> name and a .class extension

A typo maybe? It should be java HelloWorldApp

> Exception in thread "main" java.lang.noclassdef

This question has been asked a lot of times on almost all java related message boards. Have you tired a web search with the given error message? Have you tried the solutions suggested in the existing threads?

BTW, the `java' command expects a "package qualified" class name and not just a class name. So if you are using a package, make sure you use the fully qualified class name when invoking `java'. If not, then executing the `java' command from the same directory in which the class file lies shouldn't be a problem as such.

Also, is the NoClassDefFoundError error thrown for the main class or some other class which the main class is using? In this case, you might have unresolved runtime dependencies which you will have to resolve by setting the appropriate classpath entries.
I don't accept change; I don't deserve to live.
Reply With Quote Quick reply to this message  
Join Date: May 2009
Posts: 9
Reputation: sgsawant is an unknown quantity at this point 
Solved Threads: 0
sgsawant's Avatar
sgsawant sgsawant is offline Offline
Newbie Poster

Re: Exception in thread "main" java.lang.noclassdef............

 
0
  #5
May 25th, 2009
Thanks for your reply. I have searched using google the error I have posted above. I thoroughly exhausted the first 10 results given by google; after which the solutions have become repetitive.

I believe I have set the paths correctly. Yet as has been suggested on many threads I also asked java to look into the same folder for the class file. One of the ways in which I tried doing that was:
java -classpath . HelloWorldApp
(this i did right after javac command successfully created the .class file)
Yet I am facing the same errors.

To see if the problem is universal I tried a java program which I knew worked. It came with a camera I have installed on 1 of my robot.
After copying it to an arbitrary folder (C:\jtemp) I tried
java CMUcamGUI
Which gave errors. Thinking that it may be because of the path I tried the following:
java -classpath . CMUcamGUI

This time the program worked and opened up the expected interface. Buoyed by this success I copied the HelloWorldApp.java file to the folder C:\jtemp
I compiled it using the javac command. That was successful as the .class file appeared right besides it.

Now when I tried the same method:
java -classpath . HelloWorldApp
I am still receiving the same errors. Is there a way around this problem? Please help.
Last edited by sgsawant; May 25th, 2009 at 4:13 am.
Reply With Quote Quick reply to this message  
Join Date: Jun 2006
Posts: 7,609
Reputation: ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of 
Solved Threads: 464
Super Moderator
Featured Poster
~s.o.s~'s Avatar
~s.o.s~ ~s.o.s~ is offline Offline
Failure as a human

Re: Exception in thread "main" java.lang.noclassdef............

 
0
  #6
May 25th, 2009
Post the code of the class "as it is" without *any* modification, including the package declaration. Also paste the *exact* error message along with a screenshot of the entire session.

This shouldn't be happening if you are well aware of the points I mentioned in my previous post.
I don't accept change; I don't deserve to live.
Reply With Quote Quick reply to this message  
Join Date: Oct 2008
Posts: 2,612
Reputation: adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of 
Solved Threads: 463
Moderator
adatapost's Avatar
adatapost adatapost is offline Offline
Posting Maven

Re: Exception in thread "main" java.lang.noclassdef............

 
0
  #7
May 25th, 2009
I think your classname is different then your .java file. After you compiled a .java file, a .class file will be produced. Determine the name of .class file and try to execute with,

>java classname

NOTE: Lets us know the version of jdk you are using.
Failure is not fatal, but failure to change might be. - John Wooden
Reply With Quote Quick reply to this message  
Join Date: May 2009
Posts: 9
Reputation: sgsawant is an unknown quantity at this point 
Solved Threads: 0
sgsawant's Avatar
sgsawant sgsawant is offline Offline
Newbie Poster

Re: Exception in thread "main" java.lang.noclassdef............

 
0
  #8
May 26th, 2009
To write the program I used Netbeans IDE 6.5.1
The version of my JDK is 1.6.0_13

My program is as follows
  1. /*
  2.  * To change this template, choose Tools | Templates
  3.  * and open the template in the editor.
  4.  */
  5.  
  6. package helloworldapp;
  7.  
  8. /**
  9.  *
  10.  * @author Shashank Sawant
  11.  */
  12. public class HelloWorldApp {
  13.  
  14. /**
  15.   * @param args the command line arguments
  16.   */
  17. public static void main(String[] args) {
  18. System.out.println("Hello World!");
  19. }
  20.  
  21. }

The source file is stored at the following address on my hard disk:
C:\Documents and Settings\Shashank Sawant\My Documents\NetBeansProjects\HelloWorldApp\src\helloworldapp\HelloWorldApp.java

The compiled file is stored at the address:
C:\Documents and Settings\Shashank Sawant\My Documents\NetBeansProjects\HelloWorldApp\src\helloworldapp\HelloWorldApp.class

One seemingly important thing I discovered after viewing the properties of the HelloWorldApp.class file through the Netbeans IDE is that it had the following "Runtime Classpath":
C:\Documents and Settings\Shashank Sawant\My Documents\NetBeansProjects\HelloWorldApp\build\classes

Following link is the screenshot of the error and a few commands that have preceded it:
I have tried to commands after compiling the HelloWorldApp.java file. One is the simple "java HelloWorldApp" {the last but one error} and the second is "java -classpath . HelloWorldApp
Both produce failure.
http://1.bp.blogspot.com/_NpujkFKQb0w/ShuJI7so4pI/AAAAAAAAMf8/DsT1qyhS6eQ/s1600-h/Java+Error+1.JPG


I have linked the image as I was unable to find a method to upload the image on this post. I guess there is none. Thank You for considering my error and trying to help me out.

Regards,

-sgsawant
Reply With Quote Quick reply to this message  
Join Date: Jun 2006
Posts: 7,609
Reputation: ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of 
Solved Threads: 464
Super Moderator
Featured Poster
~s.o.s~'s Avatar
~s.o.s~ ~s.o.s~ is offline Offline
Failure as a human

Re: Exception in thread "main" java.lang.noclassdef............

 
0
  #9
May 26th, 2009
Let me again point you to my first post in this thread which clearly mentioned:
BTW, the `java' command expects a "package qualified" class name and not just a class name. So if you are using a package, make sure you use the fully qualified class name when invoking `java'. If not, then executing the `java' command from the same directory in which the class file lies shouldn't be a problem as such.
Does that ring a bell? Think what could have gone wrong, give it a second try and reproduce the entire session again in case you still face problems.

BTW, it's advisable to have the project placed in your personal folder; something like D:\personal\projects to avoid dealing with excessively long paths which IMO is messy.
Last edited by ~s.o.s~; May 26th, 2009 at 3:56 am.
I don't accept change; I don't deserve to live.
Reply With Quote Quick reply to this message  
Join Date: Oct 2008
Posts: 2,612
Reputation: adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of 
Solved Threads: 463
Moderator
adatapost's Avatar
adatapost adatapost is offline Offline
Posting Maven

Re: Exception in thread "main" java.lang.noclassdef............

 
0
  #10
May 26th, 2009
Because of this statement
  1. package helloworldapp;
  2. ..
  3. ..

you have to change the your method of compilation and also execution.

If package is mentioned then your .class must be placed under the package named folder.

Now, compile your program
>javac HelloWorldApp.java -d .

>java helloworldapp.HelloWorldApp

Note:
>javac HelloWorldApp.java -d .
where, -d option create a package folder and
. means current folder
>java helloworldapp.HelloWorldApp

If class definition placed inside the package then qualify the class with package name.
Failure is not fatal, but failure to change might be. - John Wooden
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC