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

2013/1/10

can somone tell me whats wrong with this code please.

1
2
theuberjew theuberjew

2013/1/17

#
Im getting this error now java.lang.NullPointerException at enemy.enemyHit(enemy.java:76) at enemy.act(enemy.java:23) at greenfoot.core.Simulation.actActor(Simulation.java:507) at greenfoot.core.Simulation.runOneLoop(Simulation.java:470) at greenfoot.core.Simulation.runContent(Simulation.java:204) at greenfoot.core.Simulation.run(Simulation.java:194)
danpost danpost

2013/1/17

#
In order to work with List object, the List class must be imported into your class with
import java.util.List;
However, this would be more to the point and not require importing java.util.List:
public boolean enemyHit()
{
    return getOneIntersectingObject(Enemy.class) != null;
}
Knowing where to go to find what methods are available is of the upmost importance. You do not neccessarily have to learn each method inside and out. Just knowing that there is a method that does a specific thing is enough, because then you just go back to the information on it and utilize it. With practice, you will find yourself going back to the documentation less and less. Best place to start is with the Greenfoot package APIs through the 'Documentation' link at the top of the page. In the reference section, select 'online' and quickly browse through the methods in each class to see what is available.
You need to login to post a reply.
1
2