Results 1 to 7 of 7
- 02-24-2009, 02:25 PM #1
Member
- Join Date
- Feb 2009
- Posts
- 4
- Rep Power
- 0
Error message in executing a simple program from DOS window
Dear All,
I simply copy/pasted a hello world program with a window that pops up.
This is the sequence of steps I accomplished:
C:\tmp>javac HelloWorldSwing.java
C:\tmp>dir
24/02/2009 14:10 <DIR> .
24/02/2009 14:10 <DIR> ..
24/02/2009 14:10 439 HelloWorldSwing$1.class
24/02/2009 14:10 988 HelloWorldSwing.class
24/02/2009 13:12 2,654 HelloWorldSwing.java
So I say, OK now I can execute the program (by the way, why does it create a HelloWorldSwing$1.class file?)
C:\tmp>java -cp . HelloWorldSwing
Exception in thread "main" java.lang.NoClassDefFoundError: HelloWorldSwing (wron
g name: start/HelloWorldSwing)
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(Unknown Source)
at java.security.SecureClassLoader.defineClass(Unknow n 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)
Could not find the main class: HelloWorldSwing. Program will exit.
These are the environment variables PATH and CLASSPATH
CLASSPATH contains C:\Program Files\Java\jdk1.6.0_12\lib
PATH contains C:\Program Files\Java\jdk1.6.0_12\bin
I don't know what else to look for, previous posts seem to direct people only to check if they are running "java.exe" or to the correct classpath but they both seem fine...
Any help is appreciated.
thanks
Nicola
- 02-24-2009, 02:30 PM #2
Senior Member
- Join Date
- Dec 2008
- Location
- Kolkata
- Posts
- 280
- Rep Power
- 5
It seems that your class containing the main method is inside a package , try to following to execute
c:\tmp> javac -cp . start/HelloWorldSwing
- 02-24-2009, 02:39 PM #3
Member
- Join Date
- Feb 2009
- Posts
- 4
- Rep Power
- 0
It doesn't work. This is what it returns:
C:\tmp>java -cp . start/HelloWorldSwing
Exception in thread "main" java.lang.NoClassDefFoundError: start/HelloWorldSwing
Caused by: java.lang.ClassNotFoundException: start.HelloWorldSwing
at java.net.URLClassLoader$1.run(URLClassLoader.java: 200)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.j ava:188)
at java.lang.ClassLoader.loadClass(ClassLoader.java:3 07)
at sun.misc.Launcher$AppClassLoader.loadClass(Launche r.java:301)
at java.lang.ClassLoader.loadClass(ClassLoader.java:2 52)
at java.lang.ClassLoader.loadClassInternal(ClassLoade r.java:320)
Could not find the main class: start/HelloWorldSwing. Program will exit.
Tha main method is in the HelloWorldSwing class.
- 02-24-2009, 02:42 PM #4
Senior Member
- Join Date
- Dec 2008
- Location
- Kolkata
- Posts
- 280
- Rep Power
- 5
Have you defined the class inside any package? Could you please paste the code here.
- 02-24-2009, 02:46 PM #5
Member
- Join Date
- Feb 2009
- Posts
- 4
- Rep Power
- 0
Now It works.
In the code lines there was the following statement:
package start;
I'm new to Java so I don't know about this yet. The only thing I know is that getting rid of it made the program work which is already good enough.
Still I would like to understand why it didn't work with that statement....
- 02-24-2009, 02:46 PM #6
Senior Member
- Join Date
- Dec 2008
- Location
- Kolkata
- Posts
- 280
- Rep Power
- 5
ok, probably I got it, before you paste your code try this first
c:\tmp> javac -d . HelloWorldSwing.java
c:\tmp> java -cp . start/HelloWorldSwing
- 02-24-2009, 02:50 PM #7
Senior Member
- Join Date
- Dec 2008
- Location
- Kolkata
- Posts
- 280
- Rep Power
- 5
Similar Threads
-
Executing an external java program
By arunsubramanian in forum Advanced JavaReplies: 5Last Post: 02-06-2009, 07:49 AM -
[SOLVED] Error executing Jar file
By VeasMKII in forum New To JavaReplies: 3Last Post: 01-31-2009, 05:32 AM -
Error Occurred Executing Command Line Solution
By RahulKhire in forum EclipseReplies: 1Last Post: 09-10-2008, 01:38 PM -
help-executing the program
By j2vdk in forum New To JavaReplies: 6Last Post: 08-30-2008, 09:18 PM -
Error When Executing Query
By radz in forum New To JavaReplies: 5Last Post: 06-26-2008, 03:37 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks