I have a very simple program for a homework assignment, I’m trying to group bills by years and months using a class called “Payment” (terrible name, I know) that I store within an ArrayList (I’m open to suggestions for a better container).
However I get a strange error message from Eclipse (will put at end).
public class Payment {
private double[] Month;
private int Year;
private boolean Paid;
....
// A lot of setters, getters, nothing important
}
Now I want to create an array list
import java.util.ArrayList;
public class Bill {
ArrayList<Payment> Money = new ArrayList<Payment>();
Money. // error -> Money didn't get highlighted, intellisense did not provide
// a list of methods
Error reads as follows:
Multiple markers at this line:
Syntax error, insert "enum Identifier" to complete EnumHeaderName
Syntax error on token "Money", delete this token
Syntax error on token "Money", delete this token
Syntax error, insert "EnumBody" to complete EnumDeclaration
I have absolutely no idea why this happens. I went in my main file to test this out, it works there, just not here, within the “Bill” class, which is basically empty right now.
Seems like you are trying to call some
ArrayListmethod onMoneyreference.Note that, you cannot have statements like that directly inside the class. You need to have some
methodwhere you can put it.Here’s an example: –
If you put
Money.size()outside all the methods, it will be a compiler error.: –
However, you can have the call on the RHS, to assign the return value to an int: –