Results 1 to 7 of 7
  1. #1
    betelgeuse is offline Member
    Join Date
    Feb 2009
    Posts
    4
    Rep Power
    0

    Default 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

  2. #2
    dswastik is offline Senior Member
    Join Date
    Dec 2008
    Location
    Kolkata
    Posts
    283
    Rep Power
    7

    Default

    It seems that your class containing the main method is inside a package , try to following to execute

    c:\tmp> javac -cp . start/HelloWorldSwing

  3. #3
    betelgeuse is offline Member
    Join Date
    Feb 2009
    Posts
    4
    Rep Power
    0

    Cool

    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.

  4. #4
    dswastik is offline Senior Member
    Join Date
    Dec 2008
    Location
    Kolkata
    Posts
    283
    Rep Power
    7

    Default

    Have you defined the class inside any package? Could you please paste the code here.

  5. #5
    betelgeuse is offline Member
    Join Date
    Feb 2009
    Posts
    4
    Rep Power
    0

    Default

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

  6. #6
    dswastik is offline Senior Member
    Join Date
    Dec 2008
    Location
    Kolkata
    Posts
    283
    Rep Power
    7

    Default

    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

  7. #7
    dswastik is offline Senior Member
    Join Date
    Dec 2008
    Location
    Kolkata
    Posts
    283
    Rep Power
    7

    Default

    And one more thing from that tmp directory delete the .class files already created, then perform the above steps.

Similar Threads

  1. Executing an external java program
    By arunsubramanian in forum Advanced Java
    Replies: 5
    Last Post: 02-06-2009, 08:49 AM
  2. [SOLVED] Error executing Jar file
    By VeasMKII in forum New To Java
    Replies: 3
    Last Post: 01-31-2009, 06:32 AM
  3. Error Occurred Executing Command Line Solution
    By RahulKhire in forum Eclipse
    Replies: 1
    Last Post: 09-10-2008, 02:38 PM
  4. help-executing the program
    By j2vdk in forum New To Java
    Replies: 6
    Last Post: 08-30-2008, 10:18 PM
  5. Error When Executing Query
    By radz in forum New To Java
    Replies: 5
    Last Post: 06-26-2008, 04:37 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •