This site requires JavaScript, please enable it in your browser!
Greenfoot back
Notted
Notted wrote ...

2019/2/28

nullPointerExecption error for hit detection

1
2
Notted Notted

2019/2/28

#
Zestix wrote...
I don't think you have to do it that way. Can't you just remove it buy using the command removeTouching(worldBullet.class); ?
It does but does not solve the problem of the wall disappearing, causing crashes.
Super_Hippo Super_Hippo

2019/2/28

#
The problem happens because you remove the actor from the world in the wallCollapse-method and then, you are using the world the actor is in in the wallTakesAHit-method (isTouching requires the actor to be in a world). But since it was removed, the error tells you that it was removed.
Notted Notted

2019/2/28

#
So we need to find some sort of way to detect when the bullets the wall, other than
 public boolean hasHitWall()
    {
       boolean hitWall = isTouching(spaceWall.class);
       return hitWall;
    }
which causes errors.
danpost danpost

2019/2/28

#
All along, you only needed to switch the two lines in the act method of your spaceWall class.
Notted Notted

2019/3/1

#
danpost wrote...
All along, you only needed to switch the two lines in the act method of your spaceWall class.
I'm not sure that matters.
danpost danpost

2019/3/1

#
Notted wrote...
I'm not sure that matters.
All you need to do is try it (from your original code) to find out.
Notted Notted

2019/3/1

#
I just did and it works. I think that's due to how Java reads calls.
danpost danpost

2019/3/1

#
Notted wrote...
I just did and it works. I think that's due to how Java reads calls.
No. It is due to your wallCollapse method removing the actor and then your wallTakesAHit method using getWorld, which would then be null.
You need to login to post a reply.
1
2