Click here to Skip to main content
14,699,613 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> 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("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){

	public Course(String argCourseId, String argCourseName){

What I have tried:

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

1 solution

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.
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!

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