I was in need of a dynamic "database" of objects and after some research, decided to use ArrayList. However, I cannot modify the arraylist with the code as follows:
public static ArrayList cprofiles;
...
cprofiles = new ArrayList();
...
...
Customer newc = new Customer (lna, fna, sinum, year, month, day);
cprofiles.add (newc);
After this declaration, I am trying to call to methods within the object using the following format cprofiles.get(0).getName()
but I am getting an error stating
cannot find symbol (pointing to .getName())
when I try to compile the program. I have spent about an hour researching the proper method to modify this in an ArrayList but the sources I have found seem to suggest that I what I am doing is indeed correct. Please aid me spotting my error and how I may fix it.
Thanks!
cprofiles.get(0)
need to be casted (or the list to benew ArrayList<Customer>()
).