469,271 Members | 1,484 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,271 developers. It's quick & easy.

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

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

PLEASE HELP!!!


Expand|Select|Wrap|Line Numbers
  1. // Student.java
  2. // creates a class to store info about a student
  3.  
  4. class Student
  5. {
  6.     // the private data members
  7.     private int IDnumber;
  8.     private int hours;
  9.     private int points;
  10.  
  11.     // constructor added in last part of project
  12.     Student()
  13.     {
  14.         IDnumber = 77375;
  15.         points = 12;
  16.         hours = 3;
  17.     }
  18.     // end of constructor
  19.  
  20.     // the public get and set methods
  21.     public void setIDnumber(int number)
  22.     {
  23.         IDnumber = number;
  24.     }
  25.  
  26.  
  27.     public int getPoints()
  28.     {
  29.         return points;
  30.     }
  31.  
  32.     // methods to display the fields
  33.     public void showIDnumber()
  34.     {
  35.         System.out.println("ID Number is: " + IDnumber);
  36.     }
  37.  
  38.     public void showHours()
  39.     {
  40.         System.out.println("Credit Hours: " + hours);
  41.     }
  42.  
  43.     public void showPoints()
  44.     {
  45.         System.out.println("Points Earned: " + points);
  46.     }
  47.  
  48.     public double getGradePoint()
  49.     {
  50.         return (double)points / hours;
  51.     }
  52.  
  53. }
  54.  
  55.  
  56.  
  57. // ShowStudent.java
  58. // client to test the Student class
  59.  
  60. class ShowStudent
  61. {
  62.     public static void main (String args[])
  63.     {
  64.         student pupil = new student();
  65.  
  66.  
  67.         pupil.showIDnumber();
  68.         pupil.showPoints();
  69.         pupil.showHours();
  70.         System.out.println("The grade point average of the studnet created by constructor is "
  71.             + pupil.getGradePoint()+"\n\n");
  72.  
  73.         Student s2 = new Student();
  74.         s2.setIDnumber(12345);
  75.         s2.setPoints(66);
  76.         s2.setHours(20);
  77.         s2.showIDnumber();
  78.         s2.showPoints();
  79.         s2.showHours();
  80.         System.out.println("The grade point average of another student is "
  81.             + s2.getGradePoint()+"\n");
  82.  
  83.     }
  84. }
Feb 16 '08 #1
15 5544
Ganon11
3,652 Expert 2GB
In ShowStudent, you say:

Expand|Select|Wrap|Line Numbers
  1. student pupil = new student();
but the Student class is spelled with a capital S, like you used for s2:

Expand|Select|Wrap|Line Numbers
  1. Student s2 = new Student();
The compiler is looking for a separate class named student, which doesn't exist.
Feb 16 '08 #2
I changed the the S to uppercase, but I still get the same errors...
Feb 16 '08 #3
Ganon11
3,652 Expert 2GB
Can you copy/paste the exact errors? Put them between [code] tags so they are easier to read, please.
Feb 16 '08 #4
Here is the uptated ShowStudent.java 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...


Expand|Select|Wrap|Line Numbers
  1. // ShowStudent.java
  2. // client to test the Student class
  3.  
  4. public class ShowStudent
  5. {
  6.     public static void main (String args[])
  7.     {
  8.         Student pupil = new Student();
  9.  
  10.  
  11.         pupil.showIDnumber();
  12.         pupil.showPoints();
  13.         pupil.showHours();
  14.         System.out.println("The grade point average of the studnet created by constructor is "
  15.             + pupil.getGradePoint()+"\n\n");
  16.  
  17.         Student s2 = new Student();
  18.         s2.setIDnumber(12345);
  19.         s2.setPoints(66);
  20.         s2.setHours(20);
  21.         s2.showIDnumber();
  22.         s2.showPoints();
  23.         s2.showHours();
  24.         System.out.println("The grade point average of another student is "
  25.             + s2.getGradePoint()+"\n");
  26.  
  27.     }
  28. }
Feb 16 '08 #5
I have set comments to the problem areas...

Expand|Select|Wrap|Line Numbers
  1. // ShowStudent.java
  2. // client to test the Student class
  3.  
  4. public class ShowStudent
  5. {
  6.     public static void main (String args[])
  7.     {
  8.         Student pupil = new Student();// 2 cannot resolve sybmol... points to 'S' in Student 
  9.  
  10.  
  11.         pupil.showIDnumber();
  12.         pupil.showPoints();
  13.         pupil.showHours();
  14.         System.out.println("The grade point average of the studnet created by constructor is "
  15.             + pupil.getGradePoint()+"\n\n");
  16.  
  17.         Student s2 = new Student();// 2 cannot resolve sybmol points to 'S in Student
  18.         s2.setIDnumber(12345);
  19.         s2.setPoints(66);
  20.         s2.setHours(20);
  21.         s2.showIDnumber();
  22.         s2.showPoints();
  23.         s2.showHours();
  24.         System.out.println("The grade point average of another student is "
  25.             + s2.getGradePoint()+"\n");
  26.  
  27.     }
  28. }
Feb 16 '08 #6
Ganon11
3,652 Expert 2GB
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.
Feb 16 '08 #7
Yes...

Both are in C:\Error...
Feb 16 '08 #8
The exercise says that I have to use two files...

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

No dice...
Feb 16 '08 #9
Ganon11
3,652 Expert 2GB
Try compiling Student.java first? Other than that, I don't know how to help you.
Feb 16 '08 #10
I've been compiling the Student.java file first...

I'll try compile ShowStudent.java first...

Thanks anyway...
Feb 16 '08 #11
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.java
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.NoClassDefFoundError: Student
Caused by: java.lang.ClassNotFoundException: Student
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)

C:\Error>javac ShowStudent.java
ShowStudent.java:8: cannot find symbol
symbol : class Student
location: class ShowStudent
Student pupil = new Student();// 2 cannot resolve sybmol... points to 'S' in Student
^
ShowStudent.java:8: cannot find symbol
symbol : class Student
location: class ShowStudent
Student pupil = new Student();// 2 cannot resolve sybmol... points to 'S' in Student
^
ShowStudent.java:17: cannot find symbol
symbol : class Student
location: class ShowStudent
Student s2 = new Student();// 2 cannot resolve sybmol points to 'S in Student
^
ShowStudent.java: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.NoClassDefFoundError: ShowStudent
Caused by: java.lang.ClassNotFoundException: ShowStudent
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)

C:\Error>
Feb 17 '08 #12
Laharl
849 Expert 512MB
Looks to me like this folder isn't in your classpath.
Feb 17 '08 #13
gaya3
184 100+
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.java file...

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

PLEASE HELP!!!


Expand|Select|Wrap|Line Numbers
  1. // Student.java
  2. // creates a class to store info about a student
  3.  
  4. class Student
  5. {
  6.     // the private data members
  7.     private int IDnumber;
  8.     private int hours;
  9.     private int points;
  10.  
  11.     // constructor added in last part of project
  12.     Student()
  13.     {
  14.         IDnumber = 77375;
  15.         points = 12;
  16.         hours = 3;
  17.     }
  18.     // end of constructor
  19.  
  20.     // the public get and set methods
  21.     public void setIDnumber(int number)
  22.     {
  23.         IDnumber = number;
  24.     }
  25.  
  26.  
  27.     public int getPoints()
  28.     {
  29.         return points;
  30.     }
  31.  
  32.     // methods to display the fields
  33.     public void showIDnumber()
  34.     {
  35.         System.out.println("ID Number is: " + IDnumber);
  36.     }
  37.  
  38.     public void showHours()
  39.     {
  40.         System.out.println("Credit Hours: " + hours);
  41.     }
  42.  
  43.     public void showPoints()
  44.     {
  45.         System.out.println("Points Earned: " + points);
  46.     }
  47.  
  48.     public double getGradePoint()
  49.     {
  50.         return (double)points / hours;
  51.     }
  52.  
  53. }
  54.  
  55.  
  56.  
  57. // ShowStudent.java
  58. // client to test the Student class
  59.  
  60. class ShowStudent
  61. {
  62.     public static void main (String args[])
  63.     {
  64.         student pupil = new student();
  65.  
  66.  
  67.         pupil.showIDnumber();
  68.         pupil.showPoints();
  69.         pupil.showHours();
  70.         System.out.println("The grade point average of the studnet created by constructor is "
  71.             + pupil.getGradePoint()+"\n\n");
  72.  
  73.         Student s2 = new Student();
  74.         s2.setIDnumber(12345);
  75.         s2.setPoints(66);
  76.         s2.setHours(20);
  77.         s2.showIDnumber();
  78.         s2.showPoints();
  79.         s2.showHours();
  80.         System.out.println("The grade point average of another student is "
  81.             + s2.getGradePoint()+"\n");
  82.  
  83.     }
  84. }

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 "ShowStudent" class..
Even this causes "cannot resolve" problem

-Hamsa
Feb 26 '08 #14
sukatoa
539 512MB
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.java 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?
Feb 26 '08 #15
JosAH
11,448 Expert 8TB
This is a simple classpath problem. The javac compiler and the java virtual machine
don't know where to look for the class file Student after it started running the
other class. Simply add the classpath variable to them like this:

Expand|Select|Wrap|Line Numbers
  1. javac -cp . *.java 
  2. ...
  3. java -cp . ShowStudent
  4.  
The first line compiles both java files and sets the classpath to the current
directory (it reads: minus-c-p-space-dot). The last line runs your class given the
same classpath value.

kind regards,

Jos
Feb 26 '08 #16

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

1 post views Thread by Java script Dude | last post: by
1 post views Thread by Tony Johansson | last post: by
1 post views Thread by vsp15584 | last post: by
1 post views Thread by Charles Sherman | last post: by
1 post views Thread by CARIGAR | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.