NetBeans Forums
| View previous topic :: View next topic |
| Author |
Message |
DarkArchon
Joined: 23 Sep 2009 Posts: 2
|
Posted: Wed Sep 23, 2009 7:10 am Post subject: Exception in thread "main" java.lang.NoClassDefFoundError: |
|
|
First off, system specs...
WIndows XP SP 2, NetBeans 6.7.1, java version "1.5.0_16"
And here's my code
| Code: | /*
* HelloWorldApp.java
*
* Created on February 5, 2006, 6:43 PM
*
* To change this template, choose Tools | Template Manager
* and open the template in the editor.
*/
package helloworldapp;
/**
* The HelloWorldApp class implements an application that
* simply prints "Hello World!" to standard output.
*/
public class HelloWorldApp {
/** Creates a new instance of HelloWorldApp */
public HelloWorldApp() {
}
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
System.out.println("Hello World!"); // Display the string.
}
}
|
Simple hello world program. I compile and run it in NetBeans and everything seems to come out correctly. I see Hello World! and all. Then I try to run "java HelloWorldApp" on HelloWorldApp.class and I get a mess of error code (I'll quote it in a second). So I thought maybe I was doing something wrong. So I did the manual method. I put in ":\Sun\SDK\jdk\bin\javac HelloWorldApp.java" created a new .class and tried to run that one, got the same error. I can't figure out what I'm doing wrong.
So far I've tried
java HelloWorldApp
Java -cp . HelloWorldApp
java -classpath . helloworld
javaw HelloWorldApp
None of it seems to work. This is of course I'm running it all in the directory that my .java and .class are in "C:\Java\Hello World App\src\helloworldapp" to be exact.
Here is the error
| Quote: | java HelloWorldApp
Exception in thread "main" java.lang.NoClassDefFoundError: HelloWorldApp
Caused by: java.lang.ClassNotFoundException: HelloWorldApp
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClassInternal(Unknown Source)
Could not find the main class: HelloWorldApp. Program will exit. |
Any ideas? |
|
| Back to top |
|
 |
Arshad Noor Posted via mailing list.
|
Posted: Wed Sep 23, 2009 4:35 pm Post subject: Exception in thread "main" java.lang.NoClassDefFoundError: |
|
|
You have it in the "helloworldapp" package; you can only access
the class as follows:
java helloworldapp.HelloWorldApp
Arshad Noor
StrongAuth, Inc.
DarkArchon wrote:
| Quote: | First off, system specs...
WIndows XP SP 2, NetBeans 6.7.1, java version "1.5.0_16"
And here's my code
Code:
/*
* HelloWorldApp.java
*
* Created on February 5, 2006, 6:43 PM
*
* To change this template, choose Tools | Template Manager
* and open the template in the editor.
*/
package helloworldapp;
/**
* The HelloWorldApp class implements an application that
* simply prints "Hello World!" to standard output.
*/
public class HelloWorldApp {
/** Creates a new instance of HelloWorldApp */
public HelloWorldApp() {
}
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
System.out.println("Hello World!"); // Display the string.
}
}
Simple hello world program. I compile and run it in NetBeans and everything seems to come out correctly. I see Hello World! and all. Then I try to run "java HelloWorldApp" on HelloWorldApp.class and I get a mess of error code (I'll quote it in a second). So I thought maybe I was doing something wrong. So I did the manual method. I put in ":\Sun\SDK\jdk\bin\javac HelloWorldApp.java" created a new .class and tried to run that one, got the same error. I can't figure out what I'm doing wrong.
So far I've tried
java HelloWorldApp
Java -cp . HelloWorldApp
java -classpath . helloworld
javaw HelloWorldApp
None of it seems to work. This is of course I'm running it all in the directory that my .java and .class are in "C:\Java\Hello World App\src\helloworldapp" to be exact.
Here is the error
| Quote: | java HelloWorldApp
|
| Quote: | Exception in thread "main" java.lang.NoClassDefFoundError: HelloWorldApp
|
| Quote: | Caused by: java.lang.ClassNotFoundException: HelloWorldApp
|
| Quote: | at java.net.URLClassLoader$1.run(Unknown Source)
|
| Quote: | at java.security.AccessController.doPrivileged(Native Method)
|
| Quote: | at java.net.URLClassLoader.findClass(Unknown Source)
|
| Quote: | at java.lang.ClassLoader.loadClass(Unknown Source)
|
| Quote: | at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
|
| Quote: | at java.lang.ClassLoader.loadClass(Unknown Source)
|
| Quote: | at java.lang.ClassLoader.loadClassInternal(Unknown Source)
|
| Quote: | Could not find the main class: HelloWorldApp. Program will exit.
|
Any ideas?
|
|
|
| Back to top |
|
 |
DarkArchon
Joined: 23 Sep 2009 Posts: 2
|
Posted: Thu Sep 24, 2009 8:21 pm Post subject: |
|
|
tried java helloworldapp.HelloWorldApp Still having problems.....
| Quote: |
Directory of C:\Java\Hello World App\build\classes\helloworldapp
09/22/2009 11:13 PM <DIR> .
09/22/2009 11:13 PM <DIR> ..
09/22/2009 11:13 PM 575 HelloWorldApp.class
1 File(s) 575 bytes
2 Dir(s) 60,953,214,976 bytes free
C:\Java\Hello World App\build\classes\helloworldapp>java helloworldapp.HelloWorl
dApp
Exception in thread "main" java.lang.NoClassDefFoundError: helloworldapp/HelloWo
rldApp
Caused by: java.lang.ClassNotFoundException: helloworldapp.HelloWorldApp
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClassInternal(Unknown Source)
Could not find the main class: helloworldapp.HelloWorldApp. Program will exit.
C:\Java\Hello World App\build\classes\helloworldapp>java -classpath . helloworld
app.HelloWorldApp
Exception in thread "main" java.lang.NoClassDefFoundError: helloworldapp/HelloWo
rldApp
Caused by: java.lang.ClassNotFoundException: helloworldapp.HelloWorldApp
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClassInternal(Unknown Source)
Could not find the main class: helloworldapp.HelloWorldApp. Program will exit.
C:\Java\Hello World App\build\classes\helloworldapp> |
|
|
| Back to top |
|
 |
Arshad Noor Posted via mailing list.
|
Posted: Thu Sep 24, 2009 8:34 pm Post subject: Exception in thread "main" java.lang.NoClassDefFoundError: |
|
|
You have to be in the classes directory when you execute this -
not in the helloworldapp directory.
Package-names are treated like directories. Every component of
a package-name is a sub-directory. To find a class within a
package the CLASSPATH must be at the root of the sub-directory
where the package name begins. For example if your package-name
is com.strongauth.strongkey.app, and this project is in a folder
called /usr/local/strongkey, then when you try to execute some
class - say Main.class - in that package, you have to execute
java from /usr/local/strongkey as follows:
java com.strongauth.strongkey.app.Main
or you can be anywhere and execute:
java -cp /usr/local/strongkey com.strongauth.strongkey.app.Main
Arshad Noor
StrongAuth, Inc.
DarkArchon wrote:
| Quote: | tried java helloworldapp.HelloWorldApp Still having problems.....
| Quote: | Directory of C:\Java\Hello World App\build\classes\helloworldapp
|
| Quote: | 09/22/2009 11:13 PM <DIR> .
|
| Quote: | 09/22/2009 11:13 PM <DIR> ..
|
| Quote: | 09/22/2009 11:13 PM 575 HelloWorldApp.class
|
| Quote: | 1 File(s) 575 bytes
|
| Quote: | 2 Dir(s) 60,953,214,976 bytes free
|
| Quote: | C:\Java\Hello World App\build\classes\helloworldapp>java helloworldapp.HelloWorl
|
|
|
|
| Back to top |
|
 |
stefanimw
Joined: 29 Nov 2010 Posts: 2
|
Posted: Mon Nov 29, 2010 11:44 pm Post subject: Exception in thread "main" java.lang.NoClassDefFoundError: |
|
|
| Arshad Noor, thank you so much! I ran into the same problem as DarkArchon and your suggestion works! |
|
| Back to top |
|
 |
stefanimw
Joined: 29 Nov 2010 Posts: 2
|
Posted: Mon Nov 29, 2010 11:45 pm Post subject: Exception in thread "main" java.lang.NoClassDefFoundError: |
|
|
| Arshad Noor, thank you so much! I ran into the same problem as DarkArchon and your suggestion works! |
|
| Back to top |
|
 |
defrancr
Joined: 11 Mar 2013 Posts: 1
|
Posted: Mon Mar 11, 2013 11:25 am Post subject: |
|
|
| Thank you, this little "detail" made me mad a whole weekend. |
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum You can attach files in this forum You can download files in this forum
|
|