Finding nullpointerException : <p>Basically I am creating a simply game, I want circles to appear but they can not overlap each other when they are printed on the screen. The objects are created and then put into an arraylist and when ever another is created it needs to check its coordinates with all the others already in the arraylist to make sure its not the same. The method to check is called isCollidingWith and there is a setPosition method that actually sets the position. This is what I have.</p>

<p>This is how the object is created, I can't even get one to be created, once I get it working I would create more of these objects, hence the whole point of this.</p>

<pre><code>    Circle circle = new Circle(rng,circles);
    circles.add(circle);
</code></pre>

<p>This is the constructor for the object takes in a random number and and arraylist of circles. It starts with a while loop and sets a position for this circle it then goes into a for loop and checks if it is colliding with and of the other ones, if it is, it breaks and goes back to the top of the while loop and sets a different positions and then repeats checking if it is colliding with any of the other ones already in the arraylist.</p>

<pre><code>    public Planet(Random rng, ArrayList&lt;Circle&gt; circles){

        boolean key = true;
        while(key){

        this.graphic.setPosition(rng.nextFloat()*GameEngine.getWidth(),rng.nextFloat()*GameEngine.getHeight());

        for(int i = 0; i&lt;circles.size();i++){
            if(this.graphic.isCollidingWith(circles.get(i).graphic)){
                key = true;
                break;
            }
            else key = false;

        }

        }


    }
</code></pre>

<p>The problem is I keep getting a NullPointerException at the line in the constructor where it says this.graphic.setPosition. But I am guessing it has to do with the arraylist, because eclipse usually isn't that accurate with error positioning. If anyone could tell me what looks to be wrong here that would be great.</p>
