Michelle Frazer
Michelle Frazer

Reputation: 3

Cannot find constructor symbol

Here is my code for my Ingredient class:

public class Ingredient {

 /* Attribute declarations */
 private String name; //  name
 private int calorieCount; //calorie count

  /* Constructor */
 public Ingredient(String name, int calorieCount) {
  this.name = name;
  this.calorieCount = calorieCount;
 }

 public String getName(){
  return name;
 }

  public int getCalorieCount(){
  return calorieCount;
 }

  public static void main (String[] args)
  {
    Ingredient item1 = new Ingredient ("Butter", "100");
    System.out.println(item1);
  }
}

When I try and run it, I get a compiler error:

1 error found:
File: C:\eclipse\workspace\Assignment NEW1\Ingredient.java  [line: 28]
Error: C:\eclipse\workspace\Assignment NEW1\Ingredient.java:28: cannot find symbol
symbol  : constructor Ingredient(java.lang.String,java.lang.String)
location: class Ingredient

What am I doing wrong?

Upvotes: 0

Views: 121

Answers (3)

Yiping Wang
Yiping Wang

Reputation: 11

You are supposed to pass second parameter as int. you passed string "100“, however. change it to number 100 instead of "100".

Upvotes: 1

Yogesh Ralebhat
Yogesh Ralebhat

Reputation: 1466

Whenever you get compile time error about some symbol is not found, always remember that you have used something in your program which does not exist OR it could not be found using current class path.

Upvotes: 0

Rohit Jain
Rohit Jain

Reputation: 213223

You are passing 100 as string in your constructor: -

Ingredient item1 = new Ingredient ("Butter", "100");

Change it to: -

Ingredient item1 = new Ingredient ("Butter", 100);

Upvotes: 4

Related Questions