| | |
Exception in thread "main" java.lang.noclassdef............
Thread Solved |
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
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.
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.
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 !!!
•
•
•
•
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.
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
> 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.
> 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.
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.
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.
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.
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.
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.
>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
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
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
The version of my JDK is 1.6.0_13
My program is as follows
Java Syntax (Toggle Plain Text)
/* * To change this template, choose Tools | Templates * and open the template in the editor. */ package helloworldapp; /** * * @author Shashank Sawant */ public class HelloWorldApp { /** * @param args the command line arguments */ public static void main(String[] args) { System.out.println("Hello World!"); } }
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
Let me again point you to my first post in this thread which clearly mentioned:
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
•
•
•
•
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.
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.
Because of this statement
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.
Java Syntax (Toggle Plain Text)
package helloworldapp; .. ..
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
![]() |
Similar Threads
- Exception in thread "main" java.lang.NoClassDefFoundError: Invaders Error (Java)
- Exception in thread "main" java.lang.NoClassDefFoundError: Main/class (Java)
- Exception in thread "main" java.lang.NullPointerException error (Java)
- Exception in thread "main" java.lang.StackOverflowError (Java)
- Need help with error Exception in thread "main" java.lang.Nu (Java)
- exception in thread "main" java.lang.NoClassDefFoundError (Java)
Other Threads in the Java Forum
- Previous Thread: getting files in the linux server
- Next Thread: j2me help
| Thread Tools | Search this Thread |
911 actionlistener addball addressbook android api append applet application array arrays automation binary bluetooth button character chat class client code component consumer css csv database desktop eclipse ee error fractal ftp game givemetehcodez graphics gui html ide image integer j2me japplet java javaarraylist javac javaee javaprojects jni jpanel julia jvm linked linux list loan mac map method methods mobile netbeans newbie objects online oriented output panel phone printf problem program programming project projects properties recursion replaydirector reporting researchinmotion rotatetext rsa scanner se server service set sms software sort sql string swing test threads time transfer tree ubuntu update windows working






