954,518 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

run java application

hello

i am an absolute noob to java...took me about a day to work out how to compile a .java file to a .class file

now i cant run the .class file in DOS can anyone help me plz :(

the error i get is

"Exception in thread "main" java.lang.NoClassDefFoundError: HelloWorldApp"

thanks in advanced

xoron123
Newbie Poster
12 posts since Oct 2007
Reputation Points: 10
Solved Threads: 0
 

This is a class path problem. The class path let's Java know where to locate classes for your file. Post the command that you are using to run the program and a bit of directory information on where that class file resides.

Ezzaral
Posting Genius
Moderator
15,986 posts since May 2007
Reputation Points: 3,250
Solved Threads: 847
 

i type "java helloworldapp"

this is the directory
"C:\Documents and Settings\\My Documents\practice\java\hello world app\sr
c\helloworldapp>"

after googling this problem a number of times i get a lot of results saying that it is a classpath problem....but as a noob...this means nothing to me :(...i dont know what it is

xoron123
Newbie Poster
12 posts since Oct 2007
Reputation Points: 10
Solved Threads: 0
 

Are you running that command from directory which contains that class? Is there a package declaration in that class?

Ezzaral
Posting Genius
Moderator
15,986 posts since May 2007
Reputation Points: 3,250
Solved Threads: 847
 

yes, that directory contains the .class file as well as the.java file...i dont know what a package declaration is..i am following the java turorial by sun

http://java.sun.com/docs/books/tutorial/getStarted/cupojava/win32.html

xoron123
Newbie Poster
12 posts since Oct 2007
Reputation Points: 10
Solved Threads: 0
 

Ok, it actually looks you may just have a case-sensitivity issue with your names. If the class is called HelloWorldApp, it must reside in a file of that exact case-sensitive name. You must use the same case-sensitive name when you run it. "helloworldapp" is not the same as "HelloWorldApp".

Ezzaral
Posting Genius
Moderator
15,986 posts since May 2007
Reputation Points: 3,250
Solved Threads: 847
 

i dont understand... the ".class" must reside in another file? do you mean folder?

sorry but i really am a complete noob

here is what DOS gives me

C:\Documents and Settings\computer\My Documents\practice\java\hello world app\sr
c\HelloWorldApp>java HelloWorldApp
Exception in thread "main" java.lang.NoClassDefFoundError: HelloWorldApp (wrong
name: helloworldapp/HelloWorldApp)
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(Unknown Source)
at java.security.SecureClassLoader.defineClass(Unknown Source)
at java.net.URLClassLoader.defineClass(Unknown Source)
at java.net.URLClassLoader.access$000(Unknown Source)
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)

xoron123
Newbie Poster
12 posts since Oct 2007
Reputation Points: 10
Solved Threads: 0
 

Are you using an IDE to create your files or just notepad? If you are using an IDE, it looks like it has placed a "package helloworldapp" statement at the top of your source file. Packages are basically directories to group sets of classes together. Because of that package statement, Java expects that class to reside in the "helloworldapp" directory. It would need to be run from the directory above "helloworldapp" with the following command:

java helloworldapp.HelloWorldApp
Ezzaral
Posting Genius
Moderator
15,986 posts since May 2007
Reputation Points: 3,250
Solved Threads: 847
 

i am using an IDE (netbeans as the sun's site suggests) but typing "java helloworldapp.HelloWorldApp" does not help

this is message i get

C:\Documents and Settings\computer\My Documents\practice\java\hello world app\sr
c\HelloWorldApp>java HelloWorldApp.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)


surely it cant be this hard just to make it run the file

xoron123
Newbie Poster
12 posts since Oct 2007
Reputation Points: 10
Solved Threads: 0
 

Ok, that is because you are stuck right in the middle of things that Netbeans does to organize files in a project, which you do not yet understand, and you are trying to follow the simple notepad and command line tutorial. Either use the Hello World tutorial for Netbeans http://java.sun.com/docs/books/tutorial/getStarted/cupojava/netbeans.html or stick to the steps in the basic tutorial for Windows that you linked. Mixing the two of them is just going to cause you confusion at this point.

Ezzaral
Posting Genius
Moderator
15,986 posts since May 2007
Reputation Points: 3,250
Solved Threads: 847
 

oh i see...so if you do one the other is not necessary...sun really should make that clear...

THANKS A LOT MATE!!! :):):)

i spent all day yesterday trying to get it to work

(i will of course add to your reputation :))

xoron123
Newbie Poster
12 posts since Oct 2007
Reputation Points: 10
Solved Threads: 0
 

This question has already been solved

Post: Markdown Syntax: Formatting Help
You