I've searched for hours to a solution for this command line error.
Does anyone know why this is happening?
Code:
C:\Program Files\Java\jdk1.7.0_03\bin>javac -cp . Helloworldjava.java
C:\Program Files\Java\jdk1.7.0_03\bin>java -cp . Helloworldjava
Exception in thread "main" java.lang.NoClassDefFoundError: Helloworldjava (wrong
name: helloworldjava/Helloworldjava)
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java:791)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:14
2)
at java.net.URLClassLoader.defineClass(URLClassLoader.java:449)
at java.net.URLClassLoader.access$100(URLClassLoader.java:71)
at java.net.URLClassLoader$1.run(URLClassLoader.java:361)
at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
at java.lang.ClassLoader.loadClass(ClassLoader.java:423)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
at java.lang.ClassLoader.loadClass(ClassLoader.java:356)
at sun.launcher.LauncherHelper.checkAndLoadMain(LauncherHelper.java:476)
C:\Program Files\Java\jdk1.7.0_03\bin>dir
Volume in drive C has no label.
Volume Serial Number is 06B0-9830
Directory of C:\Program Files\Java\jdk1.7.0_03\bin
04/30/2012 01:38 PM <DIR> .
04/30/2012 01:38 PM <DIR> ..
03/08/2012 09:20 PM 14,744 appletviewer.exe
03/08/2012 09:20 PM 14,720 apt.exe
03/08/2012 09:20 PM 14,736 extcheck.exe
04/30/2012 01:38 PM 449 Helloworldjava.class
04/29/2012 09:54 PM 409 Helloworldjava.java
03/08/2012 09:20 PM 14,728 idlj.exe
03/08/2012 09:20 PM 14,720 jar.exe
03/08/2012 09:20 PM 14,736 jarsigner.exe
03/08/2012 09:20 PM 14,736 java-rmi.exe
03/08/2012 09:20 PM 188,808 java.exe
03/08/2012 09:20 PM 14,728 javac.exe
03/08/2012 09:20 PM 14,728 javadoc.exe
03/08/2012 09:20 PM 14,728 javah.exe
03/08/2012 09:20 PM 14,728 javap.exe
03/08/2012 09:20 PM 188,808 javaw.exe
03/08/2012 09:20 PM 264,584 javaws.exe
03/08/2012 09:20 PM 14,736 jconsole.exe
03/08/2012 09:20 PM 14,720 jdb.exe
03/08/2012 09:20 PM 14,728 jhat.exe
03/08/2012 09:20 PM 14,728 jinfo.exe
03/08/2012 09:20 PM 154,496 jli.dll
03/08/2012 09:20 PM 14,728 jmap.exe
03/08/2012 09:20 PM 14,720 jps.exe
03/08/2012 09:20 PM 14,736 jrunscript.exe
03/08/2012 09:20 PM 14,736 jsadebugd.exe
03/08/2012 09:20 PM 14,728 jstack.exe
03/08/2012 09:20 PM 14,728 jstat.exe
03/08/2012 09:20 PM 14,728 jstatd.exe
03/08/2012 09:20 PM 46,992 jvisualvm.exe
03/08/2012 09:20 PM 14,728 keytool.exe
03/08/2012 09:20 PM 14,728 kinit.exe
03/08/2012 09:20 PM 14,728 klist.exe
03/08/2012 09:20 PM 14,728 ktab.exe
03/08/2012 09:20 PM 827,728 msvcr100.dll
03/08/2012 09:20 PM 14,744 native2ascii.exe
03/08/2012 09:20 PM 14,728 orbd.exe
03/08/2012 09:20 PM 14,728 pack200.exe
03/08/2012 09:20 PM 14,736 policytool.exe
03/08/2012 09:20 PM 14,728 rmic.exe
03/08/2012 09:20 PM 14,728 rmid.exe
03/08/2012 09:20 PM 14,736 rmiregistry.exe
03/08/2012 09:20 PM 14,736 schemagen.exe
03/08/2012 09:20 PM 14,736 serialver.exe
03/08/2012 09:20 PM 14,736 servertool.exe
03/08/2012 09:20 PM 14,736 tnameserv.exe
03/08/2012 09:20 PM 179,600 unpack200.exe
03/08/2012 09:20 PM 14,728 wsgen.exe
03/08/2012 09:20 PM 14,736 wsimport.exe
03/08/2012 09:20 PM 14,720 xjc.exe
49 File(s) 2,441,090 bytes
2 Dir(s) 899,533,422,592 bytes free
C:\Program Files\Java\jdk1.7.0_03\bin>
Code:
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package helloworldjava;
/**
*
* @author Penguin
*/
public class Helloworldjava {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
// TODO code application logic here
System.out.println("Hello World!");
}
}
Re: I've searched for hours to a solution for this command line error.
a) I highly recommend against placing java and class files in your JDK folders. It creates and mess, but more importantly imagine updating your JDK and poof - work all gone. Place the JDK folder on the PATH, and place your work elsewhere
b) The class you wrote is part of a package. See Creating and Using Packages (The Java™ Tutorials > Learning the Java Language > Packages) You need to be at the root of the package to compile and run.
Re: I've searched for hours to a solution for this command line error.
Alright so I read over the documentation and based off of what I read I have tired these:
Code:
C:\Program Files\Java\jdk1.7.0_03\bin>java -cp . helloworldjava.Helloworldjava
Error: Could not find or load main class helloworldjava.Helloworldjava
C:\Program Files\Java\jdk1.7.0_03\bin>java -cp . helloworldjava.Helloworldjava.m
ain
Error: Could not find or load main class helloworldjava.Helloworldjava.main
C:\Program Files\Java\jdk1.7.0_03\bin>java -cp . helloworldjava.main
Error: Could not find or load main class helloworldjava.main
C:\Program Files\Java\jdk1.7.0_03\bin>
I still don't see "Hello World!" coming out. Does anyone have the solution to this?
Re: I've searched for hours to a solution for this command line error.
A package is a directory structure, place your classes in a directory structure as their packages statements define (in this case place Helloworldjava inside a directory named Helloworldjava). Then cd up to the parent directory, and javac/java the class file from there. Alternatively, remove the packages statement entirely (given you are trying hello world, I would not worry about packages at this point) and do the command line operations you posted in post 1. Further, read my first point in post 2
Re: I've searched for hours to a solution for this command line error.
I have been through that as well:
Code:
C:\Users\Penguin\Documents\NetBeansProjects\helloworldjava\build\classes\helloworldjava>dir
Volume in drive C has no label.
Volume Serial Number is 06B0-9830
Directory of C:\Users\Penguin\Documents\NetBeansProjects\helloworldjava\build\classes\helloworldjava
04/30/2012 02:07 PM <DIR> .
04/30/2012 02:07 PM <DIR> ..
04/30/2012 02:07 PM 576 Helloworldjava.class
1 File(s) 576 bytes
2 Dir(s) 899,525,861,376 bytes free
C:\Users\Penguin\Documents\NetBeansProjects\helloworldjava\build\classes\helloworldjava>java -cp . helloworldjava.main
Error: Could not find or load main class helloworldjava.main
C:\Users\Penguin\Documents\NetBeansProjects\helloworldjava\build\classes\helloworldjava>java -cp . helloworldjava.Helloworldjava
Error: Could not find or load main class helloworldjava.Helloworldjava
C:\Users\Penguin\Documents\NetBeansProjects\helloworldjava\build\classes\helloworldjava>java -cp . Helloworldjava
Exception in thread "main" java.lang.NoClassDefFoundError: Helloworldjava (wrong name: helloworldjava/Helloworldjava)
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$100(Unknown Source)
at java.net.URLClassLoader$1.run(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 sun.launcher.LauncherHelper.checkAndLoadMain(Unknown Source)
C:\Users\Penguin\Documents\NetBeansProjects\helloworldjava\build\classes\helloworldjava>java -cp . Helloworldjava.main
Error: Could not find or load main class Helloworldjava.main
C:\Users\Penguin\Documents\NetBeansProjects\helloworldjava\build\classes\helloworldjava>
Re: I've searched for hours to a solution for this command line error.
The program runs great through the NetBeans console window. What does NetBeans know that I dont yet?
Re: I've searched for hours to a solution for this command line error.
I have solved it:
Code:
C:\Users\Penguin\Documents\NetBeansProjects\helloworldjava\dist>dir
Volume in drive C has no label.
Volume Serial Number is 06B0-9830
Directory of C:\Users\Penguin\Documents\NetBeansProjects\helloworldjava\dist
04/29/2012 09:58 PM <DIR> .
04/29/2012 09:58 PM <DIR> ..
04/29/2012 09:58 PM 1,288 helloworldjava.jar
04/29/2012 09:58 PM 1,330 README.TXT
2 File(s) 2,618 bytes
2 Dir(s) 899,525,107,712 bytes free
C:\Users\Penguin\Documents\NetBeansProjects\helloworldjava\dist>java -jar helloworldjava.jar
Hello World!
C:\Users\Penguin\Documents\NetBeansProjects\helloworldjava\dist>
Developing General Java Applications - NetBeans IDE Tutorial
I wish I would have known this article was there from the get go. It would have saved me three hours of grief trying to run "Hello World!".
Re: I've searched for hours to a solution for this command line error.
Quote:
Originally Posted by
sepoto
I wish I would have known this article was there from the get go. It would have saved me three hours of grief trying to run "Hello World!".
And it would have saved me the time trying to help...without even a single thank you
Re: I've searched for hours to a solution for this command line error.
Thank you doWhile! Your help is greatly appreciated and I mean that in earnest. :D: