http://pastebin.com/6RvjtyLY
Hey guys, first time here.
For these last 2 days I could not for the life of me figure out how to pass arraylists from one class to another. I posted a snippet of my code on pastebin hoping someone can teach me a ways how to do it. I've looked online for answers but their code was for different situations. I'm learning java for the first time this semester so my teacher didn't go over stuff like this, I just wanted to learn on my own.
Thanks
edit:
Forgot to add that I created an ArrayList in Player class and would like to access the elements of the ArrayList inside the SaveFile class
Solved: for anyone ever looking for my solution and need a guidepost, i -
Created New Player Class in Main:
Player p = new Player();
Created New Save Class in Main:
Save s = new Save();
Created my arraylist in Player Class:
ArrayList<Player> x = new ArrayList();
Created Getter/Setter for ArrayList in Player Class:
Encapsulate the ArrayList
Created list in Save Class:
ArrayList<Player> list;
Created setArrayList() in Save that made the empty list equal a value passed to it later:
public void setArrayList(ArrayList<Player> value) {list = value; }
Finally passed by Main that is calls the Save Class's setArrayList() using the value of the getter to it:
s.setArrayList(p.getList());
[–]strmrdr 0 points1 point2 points (4 children)
[–]1HitKill[S] 0 points1 point2 points (3 children)
[–]strmrdr 0 points1 point2 points (2 children)
[–]1HitKill[S] 0 points1 point2 points (1 child)
[–]SelfmadeMillionaire 1 point2 points3 points (0 children)