Cannot resolve symbol?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Seral1969
    New Member
    • Feb 2008
    • 10

    Cannot resolve symbol?

    Hi, I'm new to Java...

    I've been trying to get one of my professor's examples to work...

    He says that the code is fine, but I keep getting 4 "cannot resolve symbol" errors when I try to compile the ShowStudent.jav a file...

    The code for the Student class and ShowStudent program are listed below...

    PLEASE HELP!!!


    [CODE=java]// Student.java
    // creates a class to store info about a student

    class Student
    {
    // the private data members
    private int IDnumber;
    private int hours;
    private int points;

    // constructor added in last part of project
    Student()
    {
    IDnumber = 77375;
    points = 12;
    hours = 3;
    }
    // end of constructor

    // the public get and set methods
    public void setIDnumber(int number)
    {
    IDnumber = number;
    }


    public int getPoints()
    {
    return points;
    }

    // methods to display the fields
    public void showIDnumber()
    {
    System.out.prin tln("ID Number is: " + IDnumber);
    }

    public void showHours()
    {
    System.out.prin tln("Credit Hours: " + hours);
    }

    public void showPoints()
    {
    System.out.prin tln("Points Earned: " + points);
    }

    public double getGradePoint()
    {
    return (double)points / hours;
    }

    }



    // ShowStudent.jav a
    // client to test the Student class

    class ShowStudent
    {
    public static void main (String args[])
    {
    student pupil = new student();


    pupil.showIDnum ber();
    pupil.showPoint s();
    pupil.showHours ();
    System.out.prin tln("The grade point average of the studnet created by constructor is "
    + pupil.getGradeP oint()+"\n\n");

    Student s2 = new Student();
    s2.setIDnumber( 12345);
    s2.setPoints(66 );
    s2.setHours(20) ;
    s2.showIDnumber ();
    s2.showPoints() ;
    s2.showHours();
    System.out.prin tln("The grade point average of another student is "
    + s2.getGradePoin t()+"\n");

    }
    }[/CODE]
    Last edited by Ganon11; Feb 16 '08, 07:39 PM. Reason: Please use the [CODE] tags provided.
  • Ganon11
    Recognized Expert Specialist
    • Oct 2006
    • 3651

    #2
    In ShowStudent, you say:

    [CODE=java]student pupil = new student();[/CODE]

    but the Student class is spelled with a capital S, like you used for s2:

    [CODE=java]Student s2 = new Student();[/CODE]

    The compiler is looking for a separate class named student, which doesn't exist.

    Comment

    • Seral1969
      New Member
      • Feb 2008
      • 10

      #3
      I changed the the S to uppercase, but I still get the same errors...

      Comment

      • Ganon11
        Recognized Expert Specialist
        • Oct 2006
        • 3651

        #4
        Can you copy/paste the exact errors? Put them between [CODE] tags so they are easier to read, please.

        Comment

        • Seral1969
          New Member
          • Feb 2008
          • 10

          #5
          Here is the uptated ShowStudent.jav a file...

          There are no changes to the Student.java file...

          I have a screenshot of the error, but don't know how to attach it...


          [CODE=java]// ShowStudent.jav a
          // client to test the Student class

          public class ShowStudent
          {
          public static void main (String args[])
          {
          Student pupil = new Student();


          pupil.showIDnum ber();
          pupil.showPoint s();
          pupil.showHours ();
          System.out.prin tln("The grade point average of the studnet created by constructor is "
          + pupil.getGradeP oint()+"\n\n");

          Student s2 = new Student();
          s2.setIDnumber( 12345);
          s2.setPoints(66 );
          s2.setHours(20) ;
          s2.showIDnumber ();
          s2.showPoints() ;
          s2.showHours();
          System.out.prin tln("The grade point average of another student is "
          + s2.getGradePoin t()+"\n");

          }
          }[/CODE]
          Last edited by Ganon11; Feb 16 '08, 09:46 PM. Reason: Please use the [CODE] tags provided.

          Comment

          • Seral1969
            New Member
            • Feb 2008
            • 10

            #6
            I have set comments to the problem areas...

            [CODE=java]// ShowStudent.jav a
            // client to test the Student class

            public class ShowStudent
            {
            public static void main (String args[])
            {
            Student pupil = new Student();// 2 cannot resolve sybmol... points to 'S' in Student


            pupil.showIDnum ber();
            pupil.showPoint s();
            pupil.showHours ();
            System.out.prin tln("The grade point average of the studnet created by constructor is "
            + pupil.getGradeP oint()+"\n\n");

            Student s2 = new Student();// 2 cannot resolve sybmol points to 'S in Student
            s2.setIDnumber( 12345);
            s2.setPoints(66 );
            s2.setHours(20) ;
            s2.showIDnumber ();
            s2.showPoints() ;
            s2.showHours();
            System.out.prin tln("The grade point average of another student is "
            + s2.getGradePoin t()+"\n");

            }
            }[/CODE]
            Last edited by Ganon11; Feb 16 '08, 09:46 PM. Reason: Please use the [CODE] tags provided.

            Comment

            • Ganon11
              Recognized Expert Specialist
              • Oct 2006
              • 3651

              #7
              Now we're getting somewhere.

              It looks like ShowStudent can't find the Student class - are they in the same folder?

              If you can't get it to work, try copying/pasting the main into the Student class - that way, you're only working with one file, and there shouldn't be any unresolved errors.

              Comment

              • Seral1969
                New Member
                • Feb 2008
                • 10

                #8
                Yes...

                Both are in C:\Error...

                Comment

                • Seral1969
                  New Member
                  • Feb 2008
                  • 10

                  #9
                  The exercise says that I have to use two files...

                  I've even set the Student class to public...

                  No dice...

                  Comment

                  • Ganon11
                    Recognized Expert Specialist
                    • Oct 2006
                    • 3651

                    #10
                    Try compiling Student.java first? Other than that, I don't know how to help you.

                    Comment

                    • Seral1969
                      New Member
                      • Feb 2008
                      • 10

                      #11
                      I've been compiling the Student.java file first...

                      I'll try compile ShowStudent.jav a first...

                      Thanks anyway...

                      Comment

                      • Seral1969
                        New Member
                        • Feb 2008
                        • 10

                        #12
                        Here's what happens when I compile the files...



                        02/17/2008 01:13 AM <DIR> .
                        02/17/2008 01:13 AM <DIR> ..
                        02/17/2008 01:13 AM 754 ShowStudent.jav a
                        02/16/2008 06:20 PM 885 Student.java
                        2 File(s) 1,639 bytes
                        3 Dir(s) 109,830,705,152 bytes free

                        C:\Error>javac Student.java

                        C:\Error>java Student
                        Exception in thread "main" java.lang.NoCla ssDefFoundError : Student
                        Caused by: java.lang.Class NotFoundExcepti on: Student
                        at java.net.URLCla ssLoader$1.run( Unknown Source)
                        at java.security.A ccessController .doPrivileged(N ative Method)
                        at java.net.URLCla ssLoader.findCl ass(Unknown Source)
                        at java.lang.Class Loader.loadClas s(Unknown Source)
                        at sun.misc.Launch er$AppClassLoad er.loadClass(Un known Source)
                        at java.lang.Class Loader.loadClas s(Unknown Source)
                        at java.lang.Class Loader.loadClas sInternal(Unkno wn Source)

                        C:\Error>javac ShowStudent.jav a
                        ShowStudent.jav a:8: cannot find symbol
                        symbol : class Student
                        location: class ShowStudent
                        Student pupil = new Student();// 2 cannot resolve sybmol... points to 'S' in Student
                        ^
                        ShowStudent.jav a:8: cannot find symbol
                        symbol : class Student
                        location: class ShowStudent
                        Student pupil = new Student();// 2 cannot resolve sybmol... points to 'S' in Student
                        ^
                        ShowStudent.jav a:17: cannot find symbol
                        symbol : class Student
                        location: class ShowStudent
                        Student s2 = new Student();// 2 cannot resolve sybmol points to 'S in Student
                        ^
                        ShowStudent.jav a:17: cannot find symbol
                        symbol : class Student
                        location: class ShowStudent
                        Student s2 = new Student();// 2 cannot resolve sybmol points to 'S in Student
                        ^
                        4 errors

                        C:\Error>java ShowStudent
                        Exception in thread "main" java.lang.NoCla ssDefFoundError : ShowStudent
                        Caused by: java.lang.Class NotFoundExcepti on: ShowStudent
                        at java.net.URLCla ssLoader$1.run( Unknown Source)
                        at java.security.A ccessController .doPrivileged(N ative Method)
                        at java.net.URLCla ssLoader.findCl ass(Unknown Source)
                        at java.lang.Class Loader.loadClas s(Unknown Source)
                        at sun.misc.Launch er$AppClassLoad er.loadClass(Un known Source)
                        at java.lang.Class Loader.loadClas s(Unknown Source)
                        at java.lang.Class Loader.loadClas sInternal(Unkno wn Source)

                        C:\Error>

                        Comment

                        • Laharl
                          Recognized Expert Contributor
                          • Sep 2007
                          • 849

                          #13
                          Looks to me like this folder isn't in your classpath.

                          Comment

                          • gaya3
                            New Member
                            • Aug 2007
                            • 184

                            #14
                            Originally posted by Seral1969
                            Hi, I'm new to Java...

                            I've been trying to get one of my professor's examples to work...

                            He says that the code is fine, but I keep getting 4 "cannot resolve symbol" errors when I try to compile the ShowStudent.jav a file...

                            The code for the Student class and ShowStudent program are listed below...

                            PLEASE HELP!!!


                            [CODE=java]// Student.java
                            // creates a class to store info about a student

                            class Student
                            {
                            // the private data members
                            private int IDnumber;
                            private int hours;
                            private int points;

                            // constructor added in last part of project
                            Student()
                            {
                            IDnumber = 77375;
                            points = 12;
                            hours = 3;
                            }
                            // end of constructor

                            // the public get and set methods
                            public void setIDnumber(int number)
                            {
                            IDnumber = number;
                            }


                            public int getPoints()
                            {
                            return points;
                            }

                            // methods to display the fields
                            public void showIDnumber()
                            {
                            System.out.prin tln("ID Number is: " + IDnumber);
                            }

                            public void showHours()
                            {
                            System.out.prin tln("Credit Hours: " + hours);
                            }

                            public void showPoints()
                            {
                            System.out.prin tln("Points Earned: " + points);
                            }

                            public double getGradePoint()
                            {
                            return (double)points / hours;
                            }

                            }



                            // ShowStudent.jav a
                            // client to test the Student class

                            class ShowStudent
                            {
                            public static void main (String args[])
                            {
                            student pupil = new student();


                            pupil.showIDnum ber();
                            pupil.showPoint s();
                            pupil.showHours ();
                            System.out.prin tln("The grade point average of the studnet created by constructor is "
                            + pupil.getGradeP oint()+"\n\n");

                            Student s2 = new Student();
                            s2.setIDnumber( 12345);
                            s2.setPoints(66 );
                            s2.setHours(20) ;
                            s2.showIDnumber ();
                            s2.showPoints() ;
                            s2.showHours();
                            System.out.prin tln("The grade point average of another student is "
                            + s2.getGradePoin t()+"\n");

                            }
                            }[/CODE]

                            Hi,
                            What i have observed is in"Student" file u dont have setter method for "Points" & "Hours".. but u were trying to set those variable at "ShowStuden t" class..
                            Even this causes "cannot resolve" problem

                            -Hamsa

                            Comment

                            • sukatoa
                              Contributor
                              • Nov 2007
                              • 539

                              #15
                              Originally posted by Seral1969
                              Hi, I'm new to Java...

                              I've been trying to get one of my professor's examples to work...

                              He says that the code is fine, but I keep getting 4 "cannot resolve symbol" errors when I try to compile the ShowStudent.jav a file...

                              The code for the Student class and ShowStudent program are listed below...

                              PLEASE HELP!!!

                              Are you sure of your code?

                              Maybe you forgot this,

                              at line 62, student must be Student
                              No such method as setPoints() in Student class
                              No such method as setHour() in Student class

                              make the class where the main method is to public...

                              tell us the result?

                              Comment

                              Working...