Results 1 to 7 of 7
  1. #1
    oladitan's Avatar
    oladitan is offline Member
    Join Date
    Oct 2011
    Posts
    5
    Rep Power
    0

    Default Java 7 from command Line

    Hello I am trying to run Java from windows vista cmd. It is not working. I am able to compile a java file into a class but i cannot run the class. I keep getting this message "Exception in thread "main" java.lang.NoClassDefFoundError:" Help is appreciated. thank you.



    in the video recording while in netbeans i run Welcome 2. in the command window I compile Welcome1. Welcome 1's code is slightly different but displays the same message as Welcome2. Here is the code for Welcome 1:
    Java Code:
    /*
     * To change this template, choose Tools | Templates
     * and open the template in the editor.
     */
    package welcome1;
    
    /**
     *
     * @author User
     */
    public class Welcome1 {
    
        /**
         * @param args the command line arguments
         */
        public static void main(String[] args) {
            // TODO code application logic here
            System.out.println("Welcome to Java Programming");
        } // end method main
    } // end class Welcome1
    Last edited by oladitan; 10-02-2011 at 09:58 PM.

  2. #2
    FlyNn is offline Senior Member
    Join Date
    Feb 2010
    Posts
    128
    Rep Power
    0

    Default Re: Java 7 from command Line

    Is it just me or your public class Welcome1 is commented out? how is it blue?
    Measuring programming progress by lines of code is like measuring aircraft building progress by weight.

  3. #3
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,353
    Blog Entries
    7
    Rep Power
    20

    Default Re: Java 7 from command Line

    The canonical name of your class is welcome1.Welcome1 because it is in a package named welcome1. I don't think you know how to handle packages for now so remove the package statement and try again.

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  4. #4
    oladitan's Avatar
    oladitan is offline Member
    Join Date
    Oct 2011
    Posts
    5
    Rep Power
    0

    Default Re: Java 7 from command Line

    i don't know why it looks like that on this page

    here is what it looks like in netbeans:

    Java 7 from command Line-6207277456_638ea753db.jpg
    Last edited by oladitan; 10-03-2011 at 12:19 PM.

  5. #5
    oladitan's Avatar
    oladitan is offline Member
    Join Date
    Oct 2011
    Posts
    5
    Rep Power
    0

    Default Re: Java 7 from command Line

    thankyou JosAH. I was able to run the class after I commented out "package welcome1;" and recompiled it.

  6. #6
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,353
    Blog Entries
    7
    Rep Power
    20

    Default Re: Java 7 from command Line

    Quote Originally Posted by oladitan View Post
    thankyou JosAH. I was able to run the class after I commented out "package welcome1;" and recompiled it.
    Good; if a class C is defined in a package p, it's complete name is p.C and the class file p.C.class has to be stored in a directory p under the name C.class; otherwise the system class loader can't find the file; the classpath has to point to the parent directory of direcory p. In other words: the system class loader uses your filing system to determine where those classes in packages are stored (given the classpath value). You didn't know that and you saw the results ...

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  7. #7
    oladitan's Avatar
    oladitan is offline Member
    Join Date
    Oct 2011
    Posts
    5
    Rep Power
    0

    Default Re: Java 7 from command Line

    i will keep this in mind. thankyou JosAH

Similar Threads

  1. Replies: 16
    Last Post: 09-17-2011, 02:41 AM
  2. How do you use the Mac command line for Java?
    By java beginner in forum New To Java
    Replies: 16
    Last Post: 05-07-2011, 04:34 AM
  3. Replies: 2
    Last Post: 07-02-2010, 02:20 PM
  4. Java command line
    By agouzoul in forum New To Java
    Replies: 2
    Last Post: 04-02-2008, 12:12 PM
  5. Unable to execute command line command in java
    By LordSM in forum New To Java
    Replies: 1
    Last Post: 08-08-2007, 12:23 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
  •