Results 1 to 3 of 3
  1. #1
    l flipboi l is offline Member
    Join Date
    Feb 2011
    Posts
    1
    Rep Power
    0

    Default Classes, compilation error

    Hello Everyone!

    I'm new to Java and I was wondering, why isn't this printing correctly? I get these errors:

    If I change class CreateFamily to class Main it works, but how can I make it work using CreateFamily class?


    Java Code:
    run:
    Exception in thread "main" java.lang.NoClassDefFoundError: javaapplication1/Main
    Caused by: java.lang.ClassNotFoundException: javaapplication1.Main
            at java.net.URLClassLoader$1.run(URLClassLoader.java:202)
            at java.security.AccessController.doPrivileged(Native Method)
            at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
            at java.lang.ClassLoader.loadClass(ClassLoader.java:307)
            at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
            at java.lang.ClassLoader.loadClass(ClassLoader.java:248)
    Java Result: 1
    BUILD SUCCESSFUL (total time: 0 seconds)
    Java Code:
    class Family{
    
        String lastname;
        String firstname;
        int age;
    
        //constructor
        Family(){
            lastname = " ";
            firstname = " ";
            age = 0;
    
        }
    
    }
    
    class CreateFamily {
    
    
        public static void main(String arguments[]) {
            Family f1, f2;
    
            f1 = new Family();
            f1.lastname = "smith";
            f1.firstname = "jack";
            f1.age = 99;
            System.out.println(f1.firstname + " " + f1.lastname +
                               " is " + f1.age + " years old");
    
            f2 = new Family();
            f2.lastname = "doe";
            f2.firstname = "sally";
            f2.age = 39;
            System.out.println(f2.firstname + " " + f2.lastname +
                               " is " + f2.age + " years old");
    
        }
    }

  2. #2
    NRitH is offline Senior Member
    Join Date
    Feb 2011
    Posts
    118
    Rep Power
    0

    Default

    Put main() in the Family class, delete the CreateFamily class, then run

    java Family

    on the command line.

  3. #3
    JosAH's Avatar
    JosAH is online now Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,773
    Blog Entries
    7
    Rep Power
    21

    Default

    Quote Originally Posted by l flipboi l View Post
    Java Code:
    Exception in thread "main" java.lang.NoClassDefFoundError: javaapplication1/Main
    Caused by: java.lang.ClassNotFoundException: javaapplication1.Main
    Given the error message it seems to me that you're trying to run a class Main in package javaapplication1. I can't see a class Main and I can't see a package definition javaapplication1. b.t.w. none of the classes you've shown us are public.

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

Similar Threads

  1. Compilation error I can't make any sense of
    By qoncept in forum New To Java
    Replies: 5
    Last Post: 02-02-2011, 04:41 PM
  2. Strange Compilation Error About Generics
    By dhafirnz in forum Advanced Java
    Replies: 7
    Last Post: 11-16-2010, 09:54 AM
  3. bean compilation error
    By technical_helps@yahoo.com in forum Enterprise JavaBeans (EJB)
    Replies: 0
    Last Post: 07-30-2009, 12:21 AM
  4. compilation error(version problem?)
    By Ms.Ranjan in forum New To Java
    Replies: 3
    Last Post: 07-11-2008, 05:31 PM
  5. compilation error with Jcreator
    By Heather in forum JCreator
    Replies: 2
    Last Post: 06-30-2007, 05:12 PM

Posting Permissions

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