How to properly design a method to populate an array
<p>I the beginning of my game I am creating a background that consists of star objects</p>

<pre><code>bg = new Background();
</code></pre>

<p>My background class looks like this:</p>

<pre><code>public class Background {

    public ArrayList&lt;Star&gt; starList;
    private Star star;

    public Background(int level) {
        star = new Star();
        star.populateStarList(level);
    }

    public class Star{

        private boolean stillSearching = true;
        boolean clash = false;
        public Vector2 starPositionVector;

        public Star() {
            //loop through the starList to find valid x,y coordinates
            while (stillSearching){
                float x = 0 + (int)(Math.random() * ((GamePanel.WIDTH - 0) + 1));
                float y = 0 + (int)(Math.random() * ((GamePanel.HEIGHT - 0) + 1));
                starPositionVector = new Vector2(x,y);

                for (int u = 0; u &lt; starList.size(); u++){
                    Star starCollision = starList.get(u);

                    //check distance
                    if (starPositionVector.dstSqr(starCollision.starPositionVector) &lt; 5){
                        clash = true;
                        break;
                    }
                }
                if (clash == false){
                    stillSearching = false;
                }
            }
        }


        public void populateStarList(int level){

            if(starList==null) {
                starList = new ArrayList&lt;Star&gt;();
            }

            for (int i = 0; i &lt; 10; i++){
                Star star = new Star();
                starList.add(star);
            }
        }
    }
}
</code></pre>

<p>The idea is that populateStarList will fill an array with star objects. However, I cannot call populateStarlist without instantiating the star class. This is a problem as the starList array is used in the </p>

<pre><code>public class Star
</code></pre>

<p>and is zero before the populateStarlist is called.</p>

<p>I am not sure whether this is me not understanding how to use static methods or if I've made some poor design choices.</p>

<p>ps: if there is a more effecient way to test for a valid x,y coordinate than my while/for loop I would be happy to know.</p>