這裏是我的代碼爲我的成份類:找不到構造函數符號
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);
}
}
當我嘗試和運行它,我得到一個編譯錯誤:
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
我在做什麼錯?
「String」不是「int」「100」是字符串,而「100」是「int」 –
謝謝你的幫助@PeterLawrey ...非常感謝:) –
@MichelleFrazer ..歡迎來到SO。請標記爲已接受的答案。您需要這樣做,只要你得到有用的答案你的問題。 –