title: Java - Reading from an ArrayList from another class
body: <p>We've not covered ArrayLists only Arrays and 2D arrays. What I need to do is be able to read from an ArrayList from another class. The main aim is to read from them in a for loop and use the values stored in them to display items. However, I have made this quick program to test it out and keep getting this error</p>
  
  <pre><code>java.lang.IndexOutOfBoundsException: Index: 0, Size: 0
      at java.util.ArrayList.rangeCheck(ArrayList.java:604)
      at java.util.ArrayList.get(ArrayList.java:382)
      at Main.Main(Main.java:14)
  </code></pre>
  
  <p>Here is my code</p>
  
  <pre><code>import java.util.ArrayList;
  
  public class Main
  {
      public static void Main()
      {
          System.out.println("Test");
          ArrayList &lt;Objects&gt; xcoords = new ArrayList&lt;Objects&gt;();
  
          for( int x = 1 ; x &lt; xcoords.size() ; x++ )
          {
              System.out.println(xcoords.get(x));
          }
      }
  }
  </code></pre>
  
  <p>And then the class where the ArrayList is </p>
  
  <pre><code>import java.util.ArrayList;
  
  public class Objects
  {
      public void xco()
      {
          ArrayList xcoords = new ArrayList();
          //X coords
          //Destroyable
          xcoords.add(5);
          xcoords.add(25);
          xcoords.add(5);
          xcoords.add(5);
          xcoords.add(25);
          xcoords.add(5);
          //Static Walls
          xcoords.add(600);
          xcoords.add(400);
          xcoords.add(600);
      }
  }
  </code></pre>
  
  <p>If someone can point me in the correct direction it would be so valuable. I've tried to debug however I can get anything helpful.</p>
  
  <p>Thanks in advance.</p>