title: Array Creation Stack overflow
body: <p>I'm getting an error where it would keep giving me a stack overflow. What I basically wanna do is create an Array List of objects that have rectangles. However, if any of the object overlap one another then, I would call the method again and create  an array till it creates an array of objects that do not overlap. Can anyone tell me whats wrong?</p>
  
  <pre><code>public  class TokenArrayCreator {
  public final int TOKEN_WIDTH= 35;
  
  private GameToken token1;
  private ArrayList&lt;GameToken&gt; tokenarr;
  public  TokenArrayCreator()
  {}
  
  
  public ArrayList&lt;GameToken&gt; ArrayCreator()
  {
      ArrayList&lt;GameToken&gt; tokenArray = new ArrayList&lt;GameToken&gt;();
      Random random = new Random();
      for(int i =0; i&lt;=10 ;i++)
      {
   GameToken token= new GameToken(random.nextInt(300),random.nextInt(300),35,35);
  tokenArray.add(token);
      }
  
  
      for(int i =0 ; i&lt;=10 ; i++) // make two list i and j &amp;&amp; if i != j
      { 
      for(int j= 0; j&lt;=10 ; j++)
      {
      if(i!=j)
      {
          if(tokenArray.get(i).overlaps(tokenArray.get(j)))
          {
              TokenArrayCreator t1= new TokenArrayCreator();
              t1.ArrayCreator();
          }
  
  
  
      }
      else break;
      }
  
      }
  
  
      return tokenArray;
  }  
  </code></pre>
  
  <p>Above is my array creator class. Below is my overlap method that is in another class.</p>
  
  <pre><code>public  boolean overlaps(VisibleShape other) 
  {
  
  GameToken other1 = (GameToken) other;
  if(this.bbox.intersects(other1.bbox))
  {
      return true;
  }
  else return false;
  
  
  }
  </code></pre>
  
  <p>Here is the stack trace</p>
  
  <pre><code>Exception in thread "main" java.lang.StackOverflowError
  at java.util.Hashtable.hash(Unknown Source)
  at java.util.Hashtable.get(Unknown Source)
  at javax.swing.UIDefaults.getFromHashtable(Unknown Source)
  at javax.swing.UIDefaults.get(Unknown Source)
  at javax.swing.MultiUIDefaults.get(Unknown Source)
  at javax.swing.UIDefaults.getFont(Unknown Source)
  at javax.swing.UIManager.getFont(Unknown Source)
  at javax.swing.LookAndFeel.installColorsAndFont(Unknown Source)
  at javax.swing.plaf.basic.BasicPanelUI.installDefaults(Unknown Source)
  at javax.swing.plaf.basic.BasicPanelUI.installUI(Unknown Source)
  at javax.swing.JComponent.setUI(Unknown Source)
  at javax.swing.JPanel.setUI(Unknown Source)
  at javax.swing.JPanel.updateUI(Unknown Source)
  at javax.swing.JPanel.&lt;init&gt;(Unknown Source)
  at javax.swing.JPanel.&lt;init&gt;(Unknown Source)
  at javax.swing.JPanel.&lt;init&gt;(Unknown Source)
  at CircPattern.&lt;init&gt;(CircPattern.java:25)
  at Pattern.&lt;init&gt;(Pattern.java:40)
  at GameToken.&lt;init&gt;(GameToken.java:18)
  at TokenArrayCreator.ArrayCreator(TokenArrayCreator.java:26)
  at TokenArrayCreator.ArrayCreator(TokenArrayCreator.java:40)
  at TokenArrayCreator.ArrayCreator(TokenArrayCreator.java:40)
  at TokenArrayCreator.ArrayCreator(TokenArrayCreator.java:40)
  at TokenArrayCreator.ArrayCreator(TokenArrayCreator.java:40)
  at TokenArrayCreator.ArrayCreator(TokenArrayCreator.java:40)
  </code></pre>