Java Forums

Main Menu
Home
Today's Posts
FAQ
Search
Contact Us

Java Network
Java Tips
Java Tips Blog

Sponsored Links





Welcome to the Java Forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community, you will:

  • have access to post topics
  • communicate privately with other members (PM)
  • not see advertisements between posts
  • have the possibility to earn one of our surprises if you are an active member
  • access many other special features that will be introduced later.

Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact us.

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 02-17-2008, 03:18 AM
Member
 
Join Date: Feb 2008
Posts: 2
seral1969 is on a distinguished road
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");

}
}
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 02-17-2008, 06:16 AM
gibsonrocker800's Avatar
Senior Member
 
Join Date: Nov 2007
Location: New York
Posts: 143
gibsonrocker800 is on a distinguished road
Send a message via AIM to gibsonrocker800
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.
__________________
//Haha javac, can't see me now, can ya?
Bookmark Post in Technorati
Reply With Quote
  #3 (permalink)  
Old 02-17-2008, 06:17 AM
gibsonrocker800's Avatar
Senior Member
 
Join Date: Nov 2007
Location: New York
Posts: 143
gibsonrocker800 is on a distinguished road
Send a message via AIM to gibsonrocker800
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.
__________________
//Haha javac, can't see me now, can ya?
Bookmark Post in Technorati
Reply With Quote
  #4 (permalink)  
Old 02-17-2008, 08:22 AM
Member
 
Join Date: Feb 2008
Posts: 2
seral1969 is on a distinguished road
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>
Bookmark Post in Technorati
Reply With Quote
  #5 (permalink)  
Old 02-18-2008, 01:17 AM
CaptainMorgan's Avatar
Moderator
 
Join Date: Dec 2007
Location: NewEngland, US
Posts: 839
CaptainMorgan will become famous soon enoughCaptainMorgan will become famous soon enough
Send a message via AIM to CaptainMorgan
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.
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; } }
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); // 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"); } }
Resulting output:
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.
__________________

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
to our beloved Java Forums!
(closes on September 4, 2008)
Want to voice your opinion on your IDE/Editor of choice?
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
!
Got a little Capt'n in you? (drink responsibly)
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Regarding Scanner Object -- Cannot Resolve the Symbol pascal45 New To Java 1 12-21-2007 12:12 PM
Error: cannot find symbol silvia New To Java 1 08-07-2007 06:39 AM
Error: cannot resolve symbol, help me mathias Enterprise JavaBeans 1 08-06-2007 03:46 PM
Error: cannot resolve symbol' on Person (java.lang.String, java.lang.String) baltimore New To Java 1 08-06-2007 08:45 AM
MySite/Valid.java:56: cannot resolve symbol Albert Enterprise JavaBeans 1 07-05-2007 06:49 AM


All times are GMT +3. The time now is 10:00 AM.


VBulletin, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright ©2006 - 2007, www.java-forums.org