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

2016/3/11

This line of code doesn't work with no explanation.

RussellBlo RussellBlo

2016/3/11

#
 List bulletCheck = getWorld().getObjects(Bullet.class);
        if (bulletCheck.size() != 0){
            if (getIntersectingObjects(Bullet.class) != null)
            {
          if (Greenfoot.getRandomNumber(10)<5)
        {
            getWorld().addObject(new Rock(), Greenfoot.getRandomNumber(280)+1000, Greenfoot.getRandomNumber(720));
        }
          if (Greenfoot.getRandomNumber(10)>8)
          {
              getWorld().addObject(new barrierPickup(), getX(), getY());
            }
        //getWorld().removeObject(Bullet);
        getWorld().removeObject(this);
        }
      }
The only error message received is "NullPointerException". (Occurs on the first line). I have the List code there because I was getting the NullPointerException when I tried to check getIntersectingObjects code.
danpost danpost

2016/3/11

#
The only reason to get that error message on that line is if the actor was not in the world when the line was executed. Without more of the code, one cannot specifically tell you why. Please show the complete method and the act method of the class (at least).
danpost danpost

2016/3/11

#
RussellBlo wrote...
I have the List code there because I was getting the NullPointerException when I tried to check getIntersectingObjects code.
Maybe you should show how you tried without the List code since it probably is not needed to begin with.
You need to login to post a reply.