aspose file tools*
The moose likes Beginning Java and the fly likes Error by compiling textfile Could not find the main class: HelloWorldapp.  Program will exit Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Error by compiling textfile Could not find the main class: HelloWorldapp.  Program will exit" Watch "Error by compiling textfile Could not find the main class: HelloWorldapp.  Program will exit" New topic
Author

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

Frank Thuring
Greenhorn

Joined: Aug 10, 2010
Posts: 28
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

Joined: Jan 28, 2003
Posts: 3947
    
  17

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


Steve
Frank Thuring
Greenhorn

Joined: Aug 10, 2010
Posts: 28
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

Joined: Jun 21, 2008
Posts: 423
Try:
   java HelloWorldApp
instead of:
   java HelloWorldapp
Frank Thuring
Greenhorn

Joined: Aug 10, 2010
Posts: 28
That is unfortunately not the solution.....
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

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

Joined: Aug 10, 2010
Posts: 28
I already solved the problem thanks for your advise.
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

Please follow up with details so others can learn from your experiences. Thanks!
Frank Thuring
Greenhorn

Joined: Aug 10, 2010
Posts: 28
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

Joined: Sep 29, 2008
Posts: 12617

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

Joined: Aug 09, 2010
Posts: 10
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

Joined: Sep 29, 2008
Posts: 12617

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
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

Joined: Sep 29, 2008
Posts: 12617

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.)
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Error by compiling textfile Could not find the main class: HelloWorldapp. Program will exit
 
Similar Threads
Help with running my first program.
Fresh SDK Install Won't Compile?
Exception in thread "main" java.lang.NoClassDefFoundError: MyFirstApp. Please help basic issue
errors with main class
JDK malfunction