Exception in thread "Thread-1" java.lang.NullPointerException
at java.awt.Rectangle.intersects(Rectangle.java:786)
at Robotron.intersecting(Robotron.java:182)
at Robotron.run(Robotron.java:349)
at java.lang.Thread.run(Thread.java:745)
The trouble is Here:
public void intersecting(Sprite r1, Sprite r2)
{
System.out.println("The grunts isAlive is: "+r1.isAlive+" his xpos is: "+r1.rec.x+" his ypos is: "+r1.rec.y);
if(r1.rec.intersects(r2.rec) && r1.isAlive==true && r2.isAlive==true)
{
r1.isAlive=false;
r2.isAlive=false;
}
}
The output of my System.out is: The grunts isAlive is: true his xpos is: 936 his ypos is: 478
. But for some reason its giving me a null pointer
This is how I initialize my Grunts, Maybe the issue lies there?
for(int i=0; i<grunt.length;i++)
{
int randX = (int)(Math.random()*worldx);
int randY = (int)(Math.random()*worldy);
if(hero.outerCircle.inCircle(randX,randY)!=true)
{
grunt[i] = new EnemyD4(randX,randY, worldx, worldy, 50,70);
}
if(hero.outerCircle.inCircle(randX,randY)==true)
{
randX+=100;
grunt[i] = new EnemyD4(randX,randY, worldx, worldy, 50,70);
}
}