I am writing a Java (Swing) application and I'm trying to store stuff in an ArrayList
.
My plan is to first instantiate a class, set some variables in that class and then add that class to an ArrayList
.
So I have this class:
public class CollectionClass {
private ArrayList<OwnerClass> owners;
public CollectionClass() {
owners = new ArrayList<OwnerClass>();
}
public void AddOwner(OwnerClass oc) {
owners.add(oc);
}
}
And this class:
public class OwnerClass {
public int id = 0;
public String name = "";
public String employeeNr="";
}
Now in my dialog I have this:
CollectionClass myCC;
public InvoerNewOwner(CollectionClass cc) {
myCC = cc;
btSave.setActionListener(new ActionListener() {
OwnerClass oc = new OwnerClass();
oc.name = txtOwner.getText(); <<<
oc.employeeNr = txtEmployeeNr.getText(); <<<
myCC.addOwner(oc); <<<
});
I get an error on the 3 lines marked with <<<. The error is "error: <identifier> expected
"
What am I doing wrong here?
Is this not a good way to create a collection of objects?