• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

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

 
Frank Thuring
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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

This is the code:

/**
* The HelloWorldApp class implements an application that
* simply prints "Hello World!" to standard output.
*/
class HelloWorldApp {
public static void main(String[] args) {
System.out.println("Hello World!"); // Display the string.
}
}

I don't understand why I get this message. Can someone please help me?
 
Steve Luke
Bartender
Posts: 4181
22
IntelliJ IDE Java Python
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Java is case sensitive, so HelloWorldapp is not the same as HelloWorldApp.
 
Frank Thuring
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.

D:\Java>
 
Ireneusz Kordal
Ranch Hand
Posts: 423
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Try:
   java HelloWorldApp
instead of:
   java HelloWorldapp
 
Frank Thuring
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That is unfortunately not the solution.....
 
David Newton
Author
Rancher
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Set the "-cp" option to the current directory (as far as I can tell, the source and class files are in the current directory, and the class has no package, correct?)
 
Frank Thuring
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I already solved the problem thanks for your advise.
 
David Newton
Author
Rancher
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please follow up with details so others can learn from your experiences. Thanks!
 
Frank Thuring
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I had several programms of Java. I throw everything away and installed the latest version on miy computer. My lesson was to throw away other versions of Java.
 
David Newton
Author
Rancher
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
Tim Batts
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
David Newton
Author
Rancher
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
David Newton
Author
Rancher
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.)
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic