Results 1 to 5 of 5
Thread: Cannot Resolve Symbol error...
- 02-17-2008, 02:18 AM #1
Member
- Join Date
- Feb 2008
- Posts
- 2
- Rep Power
- 0
Cannot Resolve Symbol error...
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...
It seems that ShowStudent cannot access the Student class...
They are in the same directory...
Using XP...
Command line compiler is javac...
The code for the Student class and ShowStudent program are listed below...
PLEASE HELP!!!
--------------------------------------------------------------------------
// 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.println("ID Number is: " + IDnumber);
}
public void showHours()
{
System.out.println("Credit Hours: " + hours);
}
public void showPoints()
{
System.out.println("Points Earned: " + points);
}
public double getGradePoint()
{
return (double)points / hours;
}
}
--------------------------------------------------------------------------
// ShowStudent.java
// client to test the Student class
class ShowStudent
{
public static void main (String args[])
{
Student pupil = new Student();
pupil.showIDnumber();
pupil.showPoints();
pupil.showHours();
System.out.println("The grade point average of the studnet created by constructor is "
+ pupil.getGradePoint()+"\n\n");
Student s2 = new Student();
s2.setIDnumber(12345);
s2.setPoints(66);
s2.setHours(20);
s2.showIDnumber();
s2.showPoints();
s2.showHours();
System.out.println("The grade point average of another student is "
+ s2.getGradePoint()+"\n");
}
}
- 02-17-2008, 05:16 AM #2
I'm not too sure about this ,but it might be because the classes are package access. This is because, in your class declaration statements, you didn't include an access modifier, resulting in "package" as being the default. What i mean is, you put "class Student" instead of "public class Student" and when you don't specify, it results in "package class Student". So, they might not be in the same package. This might not be the case here though, so yeah.
- 02-17-2008, 05:17 AM #3
I forgot to mention, in case you didn't know, when something is declared with package access, that thing can only be accessed by classes that are within the same package.
- 02-17-2008, 07:22 AM #4
Member
- Join Date
- Feb 2008
- Posts
- 2
- Rep Power
- 0
Tried that...
I've tried the pubic class... Still the same errors...
Below is the result of 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>
- 02-18-2008, 12:17 AM #5
Well this is certainly odd.. When I examined it, it didn't find 4 unresolved symbols, but it did find two. See the code below for the two lines I commented out- you don't have methods for what you're trying to call(setPoints, and setHours).
Please use code tags when posting code.
Java Code:// 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.println("ID Number is: " + IDnumber); } public void showHours() { System.out.println("Credit Hours: " + hours); } public void showPoints() { System.out.println("Points Earned: " + points); } public double getGradePoint() { return (double)points / hours; } }Resulting output:Java Code:// ShowStudent.java // client to test the Student class class ShowStudent { public static void main (String args[]) { Student pupil = new Student(); pupil.showIDnumber(); pupil.showPoints(); pupil.showHours(); System.out.println("The grade point average of the studnet created by constructor is " + pupil.getGradePoint()+"\n\n"); Student s2 = new Student(); s2.setIDnumber(12345); [B]// s2.setPoints(66); // s2.setHours(20);[/B] s2.showIDnumber(); s2.showPoints(); s2.showHours(); System.out.println("The grade point average of another student is " + s2.getGradePoint()+"\n"); } }
ID Number is: 77375
Points Earned: 12
Credit Hours: 3
The grade point average of the studnet created by constructor is 4.0
ID Number is: 12345
Points Earned: 12
Credit Hours: 3
The grade point average of another student is 4.0
Evidently, the code I was just using was able to get access... You may want to check your PATH & CLASSPATH variables. Otherwise, try the code above. I'm not using your system so I can't tell you what's wrong unless you provide more system info.Vote for the new slogan to our beloved Java Forums! (closes on September 4, 2008)
Want to voice your opinion on your IDE/Editor of choice? Vote now!
Got a little Capt'n in you? (drink responsibly)
Similar Threads
-
Error: cannot resolve symbol' on Person (java.lang.String, java.lang.String)
By baltimore in forum New To JavaReplies: 2Last Post: 09-18-2008, 07:30 AM -
Regarding Scanner Object -- Cannot Resolve the Symbol
By pascal45 in forum New To JavaReplies: 1Last Post: 12-21-2007, 11:12 AM -
Error: cannot find symbol
By silvia in forum New To JavaReplies: 1Last Post: 08-07-2007, 05:39 AM -
Error: cannot resolve symbol, help me
By mathias in forum Enterprise JavaBeans (EJB)Replies: 1Last Post: 08-06-2007, 02:46 PM -
MySite/Valid.java:56: cannot resolve symbol
By Albert in forum Enterprise JavaBeans (EJB)Replies: 1Last Post: 07-05-2007, 05:49 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks