Click here to Skip to main content
15,885,757 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I'm working on a small program but I keep getting this error.
<pre> symbol:   method price()
  location: variable courses of type ArrayList<Course>
UnitTest.java:13: error: cannot find symbol
    System.out.println("Credit Hours: " + c1.getCreditHours());


The error is specifically pointing to the period after c1, which i'm really confused about.

I have four of the "c's" (c1, c2, etc)
Course c1=new Course("CMB-343", "Advanced Swordsmanship","2");
  System.out.println("1.");
  System.out.println("Course Id: " + c1.getCourseId());
  System.out.println("Course Name:" + c1.getCourseName());
  System.out.println("Credit Hours: " + c1.getCreditHours());

I only get the "cannot find symbol" on the first one.

here is some more code that might be related to the error.

public Course(String argCourseId, String argCourseName, String argCreditHours){
		courseId=argCourseId;
		courseName=argCourseName;
    creditHours=argCreditHours;
	}

	public Course(String argCourseId, String argCourseName){
			courseId=argCourseId;
			courseName=argCourseName;
	    creditHours="1";
		}


What I have tried:

looking for a way to fix it by looking up similar questions.
Posted
Updated 5-Mar-20 21:44pm

1 solution

Quote:
error: cannot find symbol

The error message says it all: your code contains a symbol that hasn't been declared. A symbol can be the name of a variable, class or function.
Quote:
The error is specifically pointing to the period after c1

Since you have used c1 before, this doesn't seem to be the culprit. So look what's beyond that period: getCreditHours() . Maybe that function doesn't exist, or it goes by a different name (e. g. getCourseHours()?), or you've made a typo when defining that function. Check the definition of the Course class and see if it has the function getCreditHours. Make sure it's exactly spelled like that.

On a sidenote: why do you prefix everything in the Course class by 'course'? That's a needless duplication. Except when you don't: e. g. 'creditHours'. That's needlessly inconsistent and confusing - and it might be the source of your error.


P.S.: I have some doubts about the field creditHours: if it is what is implied by it's name, it sholdn't be a member of the Course class to start with! It is a property of the relation of students to the courses they participate in, not a property of the course, nor is it a property of the student. That might be the reason why your naming scheme broke: when deciding on the name, you actually realized it's not about the course!
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900