Error by compiling textfile Could not find the main class: HelloWorldapp. Program will exit

Hello everybody,
I work on windows and I try to run a textfile but I got an error:

D:\Java>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)
Could not find the main class: HelloWorldapp. Program will exit.

I use the command prompt and give the command: javac HelloWorldApp.java

Java is case sensitive, so HelloWorldapp is not the same as HelloWorldApp.

Steve

Frank Thuring
Greenhorn

Joined: Aug 10, 2010
Posts: 28

posted Aug 10, 2010 16:16:45

0

Hai Steve,
It still goes wrong. Also when I run the programm

D:\Java>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)
Could not find the main class: HelloWorldApp. Program will exit.

That would not lead to the error you posted above, unless you started using a version that automatically put the current directory on the classpath, but okay. Glad you got it working. What version are now using to run your application?

David Newton wrote:That would not lead to the error you posted above, unless you started using a version that automatically put the current directory on the classpath, but okay. Glad you got it working. What version are now using to run your application?

Question: could this error have been caused by adding an entry to the PATH environment variable?

Adding an entry wouldn't cause the problem to start, but adding the wrong entry wouldn't fix the error either. As long as the proper package hierarchy is on the class path it'll work, if it isn't, it won't.

Tim Batts
Greenhorn

Joined: Aug 09, 2010
Posts: 10

posted Aug 10, 2010 19:27:11

0

That's what I thought. I have jdk 1.6.0_21 and had to add an entry to the PATH variable to point to the \bin directory within the main Java directory

Oh, I misread what you wrote. Adding to the path would have even less to do with the reported error (unless there's a Java version issue regarding a default claaspath and the path entry changes which version of java is being run).

If *no* version of java was on the path you'd get a message indicating as much, not an error about not being able to find a class--java has to be runnable in order for it to report any errors. (Although it could be run using its full path.)