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!!! - // 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");
-
-
}
-
}
15 6399
In ShowStudent, you say: - student pupil = new student();
but the Student class is spelled with a capital S, like you used for s2: - Student s2 = new Student();
The compiler is looking for a separate class named student, which doesn't exist.
I changed the the S to uppercase, but I still get the same errors...
Can you copy/paste the exact errors? Put them between [code] tags so they are easier to read, please.
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... - // ShowStudent.java
-
// client to test the Student class
-
-
public 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");
-
-
}
-
}
I have set comments to the problem areas... - // ShowStudent.java
-
// 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.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();// 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.println("The grade point average of another student is "
-
+ s2.getGradePoint()+"\n");
-
-
}
-
}
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.
Yes...
Both are in C:\Error...
The exercise says that I have to use two files...
I've even set the Student class to public...
No dice...
Try compiling Student.java first? Other than that, I don't know how to help you.
I've been compiling the Student.java file first...
I'll try compile ShowStudent.java first...
Thanks anyway...
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>
Looks to me like this folder isn't in your classpath.
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!!! - // 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");
-
-
}
-
}
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
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?
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: -
javac -cp . *.java
-
...
-
java -cp . ShowStudent
-
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
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Java script Dude |
last post by:
I am investigating a solution to build all pages sent from my
application servlet in UTF-8 encoding. From what I understand, I
should be using HttpServletResponse.setCharacterEncoding("UTF-8"). The...
|
by: Tony Johansson |
last post by:
Hello!
I get compile error when compiling using the command javac from the command
terminal window(CMD).
I have just two classes which are called HelloWorld.java and Slask.java.
I have both...
|
by: vsp15584 |
last post by:
Hii..i use the coding as below :-
import java.applet.applet;
import java.awt.*;
import com.sun.j3d.utils.applet.mainframe;
import com.sun.j3d.utils.universe.*;
import...
|
by: toish |
last post by:
I have a program, aaa.java which creates an instance of another class(bbb.java).
both java files are in a package entitled 'diss'
bbb.java compiles sucessfully
aaa.java throws a cannot resolve...
|
by: adamrace |
last post by:
Hi,
i am fairly new to java and have been stuck on this for ages, basically i need to create a new object which gets a list of data from a text file, so i have this
import java.io.*;
...
|
by: Sindhu Rani |
last post by:
i hav created 3 classes in 3 different files. am gettin an error durin compilation. wat shud i do???
C:\s\source>javac -d ..\classes devtestdrive.java
devtestdrive.java:5: cannot resolve symbol...
|
by: EntryTeam |
last post by:
At the screenshots you can see what libraries I've added to project, and still - those two essential classes are missing! What's wrong? Need your help.
|
by: Charles Sherman |
last post by:
public class area
{
public static void main(Strings args)
{
int height;
int width;
int area;
int i;
int e;
for (i=1; i>=11; i++);
|
by: taylorcarr |
last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: aa123db |
last post by:
Variable and constants
Use var or let for variables and const fror constants.
Var foo ='bar';
Let foo ='bar';const baz ='bar';
Functions
function $name$ ($parameters$) {
}
...
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
| |