The part where the problem occured is in an "attack" method that is supposed to subtract some hp from the hit enemy. I get a Null Pointer Exception at the if(getOneObjectAtOffset(getImage().getWidth()/2,0,ENEMY.class).getClass() == ENEMY.class) the rest of the code works as it's supposed to when I replace the inside with a isTouching(), though that doesn't do what I need it to work properly.
timerStarted2 is from the SimpleTimer class.
if(mouse.getX()>=getX())
{
this.setImage(attack1R.getCurrentImage());
if ((getImage() != imageOne) != notImageOne)
{
notImageOne = ! notImageOne;
if (!notImageOne)
{
this.setImage(attack1R.getImages().get(4));
attack= false;
setLocation(getX(),getY()+20);
}
}
if(getOneObjectAtOffset(getImage().getWidth()/2,0,ENEMY.class).getClass() == ENEMY.class)
{
if(!timerStarted2)
{
timerStarted2 = !timerStarted2;
timer2.mark();
}
ENEMY enemy = (ENEMY) getOneIntersectingObject(ENEMY.class);
if(timer2.millisElapsed() > 200 || enemy.leben == enemy.maxLeben)
{
enemy.changeLives(-1);
timerStarted2 = !timerStarted2;
}
}
}
