Results 1 to 7 of 7
  1. #1
    toby is offline Member
    Join Date
    Jul 2007
    Posts
    40
    Rep Power
    0

    Default Error: no class definition found

    Hi, I have a program but I am having a problem getting it to run (it compiled fine).
    Its error is that there is no class definition found. I really don't know what that means or how to fix it.
    Any one know? and also I'm not sure if I saved it under the right name I saved it under Student.java, is this right?

    Java Code:
    class Student
    {
        private String firstName;
        private String lastName;
        private Address homeAddress;
        private Address schoolAddress;
        private int test1;
        private int test2;
        private int test3;
    
    
        public Student (String first, String last, Address home, Address school)
        {
            lastName=last;
            firstName=first;
            homeAddress=home;
            schoolAddress=school;
            test1=0;
            test2=0;
            test3=0;
        }
    
        
        public void setTestScore (int testNumber, int testScore)
        {
            if (testNumber == 1) 
                test1 = testScore;
            else if (testNumber == 2)
                test2 = testScore;
            else
                test3 = testScore;
        }
    
    
        public int getTestScore(int testNumber)
        {
            if (testNumber == 1)
                return test1;
            else if (testNumber == 2)
                return test2;
            else
                return test3;
        }
        
        
        public double getAverage()
        {
            return (test1 + test2 + test3)/3;
        }
        
        public String toString()
        {
            String result = firstName +"\n"+ lastName +"\n"+
                "HomeAddress: "+ homeAddress + "\n"+
                "schoolAddress: "+ schoolAddress + "\n"+
                "test1: " + "test 1" + "\n"+
                "test2: " + "test 2" + "\n"+
                "test3: " + "test 3" + "\n"+
                "average: " +this.getAverage()+"\n";
            return result;
        }
    }
    
    class Course 
    {
        static int numberStudent = 0;
        String title;
        Student student1;
        Student student2;
        Student student3;
        Student student4;
        Student student5;
    
        public Course(String courseTitle)
        {
            title=courseTitle;
        }
        
        
        public void addStudent(String first, String last, Address home, Address school)
        {   
            switch(numberStudent)
            {
                case 0: student1 = new Student(first,last,home,school);
                case 1: student2 = new Student(first,last,home,school);break;
                case 2: student3 = new Student(first,last,home,school);break;
                case 3: student4 = new Student(first,last,home,school);break;
                case 4: student5 = new Student(first,last,home,school);break;
                default: System.out.println("No More students allowed in the class");
            }
             numberStudent++;
        }
    
        
        public String toString()
        {
            String results="";
            results += student1.toString () +"n";
            results += student2.toString () +"n";
            results += student3.toString () +"n";
            results += student4.toString () +"n";
            results += student5.toString () +"n";
            return results;
        }
    
    class Address 
    {
        private String streetAddress;
        private String city;
        private String state;
        private long zipCode;
        
        public Address(String stAddress,String cityValue,String stateValue,long zip)
        {
            streetAddress = stAddress;
            city = cityValue;
            state = stateValue;
            zipCode = zip;
        }
    }
    Thanks

  2. #2
    Sircedric88 is offline Member
    Join Date
    Jul 2007
    Location
    Las Vegas
    Posts
    14
    Rep Power
    0

    Default

    Hey I'm a beginning programmer, but it seems like the test score variables were not initialized as field varialbes, therefore when initialized in one method, they are set only for that method.
    (i.e. you never initialized test 1-3 to 0 in your second method, and you never set the value for testNumber.)
    That's what I think, you have a bunch of variables (i didn't exactly know where you were goin with this, so if you tell me what you're trying to do, I could perhaps help you out

  3. #3
    cruxblack is offline Senior Member
    Join Date
    Jul 2007
    Posts
    130
    Rep Power
    0

    Default

    No class definition found means that either ur bin directory haven't been put in the environment variable, u put the wrong input when u run it ex: java student, using lowercase, or missing classpath

    Btw, one other possibilities are the access modifier, though, seen from ur code, seems like this isn't supposed to be the main class is it not?

    If, just if, this is supposed to be a main class, the error might occur brcause u didn't put a public access for the class, default modifier, like the one ur using, are only usable in subclasses within the directory or outside right?

    So, if u wanna run it from the outside, ex: cmd, it'll deny the request

    Either u put the class public with a main method, or create another class that uses this class

  4. #4
    nitinborge5 is offline Member
    Join Date
    Jul 2007
    Posts
    10
    Rep Power
    0

    Default

    Quote Originally Posted by toby View Post
    Hi, I have a program but I am having a problem getting it to run (it compiled fine).
    Its error is that there is no class definition found. I really don't know what that means or how to fix it.
    Any one know? and also I'm not sure if I saved it under the right name I saved it under Student.java, is this right?

    Java Code:
    class Student
    {
        private String firstName;
        private String lastName;
        private Address homeAddress;
        private Address schoolAddress;
        private int test1;
        private int test2;
        private int test3;
    
    
        public Student (String first, String last, Address home, Address school)
        {
            lastName=last;
            firstName=first;
            homeAddress=home;
            schoolAddress=school;
            test1=0;
            test2=0;
            test3=0;
        }
    
        
        public void setTestScore (int testNumber, int testScore)
        {
            if (testNumber == 1) 
                test1 = testScore;
            else if (testNumber == 2)
                test2 = testScore;
            else
                test3 = testScore;
        }
    
    
        public int getTestScore(int testNumber)
        {
            if (testNumber == 1)
                return test1;
            else if (testNumber == 2)
                return test2;
            else
                return test3;
        }
        
        
        public double getAverage()
        {
            return (test1 + test2 + test3)/3;
        }
        
        public String toString()
        {
            String result = firstName +"\n"+ lastName +"\n"+
                "HomeAddress: "+ homeAddress + "\n"+
                "schoolAddress: "+ schoolAddress + "\n"+
                "test1: " + "test 1" + "\n"+
                "test2: " + "test 2" + "\n"+
                "test3: " + "test 3" + "\n"+
                "average: " +this.getAverage()+"\n";
            return result;
        }
    }
    
    class Course 
    {
        static int numberStudent = 0;
        String title;
        Student student1;
        Student student2;
        Student student3;
        Student student4;
        Student student5;
    
        public Course(String courseTitle)
        {
            title=courseTitle;
        }
        
        
        public void addStudent(String first, String last, Address home, Address school)
        {   
            switch(numberStudent)
            {
                case 0: student1 = new Student(first,last,home,school);
                case 1: student2 = new Student(first,last,home,school);break;
                case 2: student3 = new Student(first,last,home,school);break;
                case 3: student4 = new Student(first,last,home,school);break;
                case 4: student5 = new Student(first,last,home,school);break;
                default: System.out.println("No More students allowed in the class");
            }
             numberStudent++;
        }
    
        
        public String toString()
        {
            String results="";
            results += student1.toString () +"n";
            results += student2.toString () +"n";
            results += student3.toString () +"n";
            results += student4.toString () +"n";
            results += student5.toString () +"n";
            return results;
        }
    
    class Address 
    {
        private String streetAddress;
        private String city;
        private String state;
        private long zipCode;
        
        public Address(String stAddress,String cityValue,String stateValue,long zip)
        {
            streetAddress = stAddress;
            city = cityValue;
            state = stateValue;
            zipCode = zip;
        }
    }
    Thanks
    hi
    do one thing copy this program and again past on new
    window and then save it with same name
    then it will work

  5. #5
    Sircedric88 is offline Member
    Join Date
    Jul 2007
    Location
    Las Vegas
    Posts
    14
    Rep Power
    0

    Default

    haha thanks, I actually learned something

  6. #6
    killer8889 is offline Member
    Join Date
    Aug 2011
    Posts
    3
    Rep Power
    0

    Default

    hey i searched alot and found a very simple solution, follow up this linnk

    hope this helps
    Last edited by sunde887; 08-28-2011 at 11:32 PM. Reason: Removed link.

  7. #7
    sunde887's Avatar
    sunde887 is offline Moderator
    Join Date
    Jan 2011
    Location
    Richmond, Virginia
    Posts
    3,069
    Blog Entries
    3
    Rep Power
    8

    Default

    This is a very old, and very dead thread, please don't resurrect threads. Closing this and editing the link out of your post.

Similar Threads

  1. Class not found Exception
    By surendra in forum Java Servlet
    Replies: 8
    Last Post: 06-09-2011, 01:52 PM
  2. Replies: 6
    Last Post: 10-08-2008, 09:09 AM
  3. Strange error message "Source not found"
    By ppayal in forum Eclipse
    Replies: 0
    Last Post: 11-25-2007, 07:19 PM
  4. Eclipse - jumping to method definition
    By Java Tip in forum Java Tip
    Replies: 0
    Last Post: 11-07-2007, 03:52 PM
  5. Error: javax.servlet.ServletException: Column not found
    By barney in forum JavaServer Pages (JSP) and JSTL
    Replies: 1
    Last Post: 08-07-2007, 08:20 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
  •