I have an arrayList of type "customer" which im trying to add some objects if same type to. when i use the add() method I get an error and a red line under that command The code works fine other than that part.
public class Admin {
public static ArrayList<Customers> customers = new ArrayList<>();
Customers owner = new Customers("admin", "admin", 0);
Customers c = new Customers("test","123",0);
customers.add(c); //error is here
customers.add(new Customers("test","123",0)); //tried this one too but it doesnt work either //it says illegal start of type and not package exists }
//normal constructor
public class Customers {
private String username;
public String password;
private int points;
private String Status;
public Customers(String username, String password, int points ) {
this.username = username;
this.password = password;
this.points = points;
}}
Admin, it is in the class scope. The other code works because they are declaring variables which will be interpreted as class fields which would not give an error, but.addcannot be used outside of a method.