Eclipse claims I have a syntax error in my call to a method on an object (quarterOneBudget). I don't understand what makes it say "Syntax error on token 'addCategory', Identifer expected after this token."
public class BudgetSpreadSheetTest {
// Create a new spreadsheet and add some budget categories.
BudgetSpreadSheet quarterOneBudget = new BudgetSpreadSheet();
quarterOneBudget.addCategory();
quarterOneBudget.addCategory();
}
It seems to me like my method call is just fine. I have defined "addCategory" in my BudgetSpreadSheet as follows.
public void addCategory(){
// Create a new category
BudgetCategory category = new BudgetCategory();
// Add it to the array list
categories.add(category);
// Update the distribution chart
this.distributionChart.addItem(category.getName(), category.getSpent());
}
Does anybody see why I am getting the syntax error?
You're trying to make those calls to addCategory()
directly inside a class, instead of in a method within the class. You need to put that code either in a method or in an initializer block.