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

Recommended Answers

All 10 Replies

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.

i type "java helloworldapp"

this is the directory
"C:\Documents and Settings\<username>\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

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

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

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)

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

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

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.

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

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.