Solved ArrayLists from multiple classes. [UNSOLVED]

Discussion in 'Plugin Development' started by benzimmer123, Feb 23, 2014.

Thread Status:
Not open for further replies.
  1. Offline

    benzimmer123

    Sorry I have been posted a lot of threads lately but I have come across a lot of problems. This is one of them... I have created an arraylist in a class and want to use it in other classes. I have looked up and found many people having the same problem, however they have solved theirs. I am struggling big time! This is my code so far...
    Thanks in advance;)

    P.S I will learn from my mistakes :)

    CODE:

    ArrayList:
    Code:java
    1. ArrayList<Player> parkour2 = new ArrayList<Player>();


    Other Class:
    Code:java
    1. public static Parkour parkour;
    2.  
    3. public LeaveGame(Parkour instance) {
    4. parkour = instance;
    5. }


    Usage:
    Code:java
    1. parkour.parkour2.add(p);
     
  2. Offline

    Ironraptor3

    Assume Class one's name is ClassOne and ClassTwo's name is Class two.

    ClassOne:
    Code:java
    1. public static ArrayList<String> list = new ArrayList<String>();
    2.  

    ClassTwo:
    Code:java
    1. ArrayList<String> list = ClassOne.list;


    I'm surprised that you couldn't find the answer to this though. I had the same problem a while ago and found it within 10 minutes
     
  3. Offline

    Rocoty

    Ironraptor3 Why use static? It kinda ruins the object oriented design.
     
  4. Offline

    Ironraptor3

    Rocoty meh. OH and don't save players to lists. I didn't see that at first
     
  5. Offline

    Minesuchtiiii



    • public static ArrayList<String[​IMG]> list = new ArrayList<String>();





    Then to get it in another class:

    private [pluginname] plugin;

    public [classname] ([pluginname] plugin) {

    this.plugin = plugin;
    }

    to get the arraylist:

    this.[your main class] .list
     
Thread Status:
Not open for further replies.

Share This Page