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

2012/12/18

hi im having a problem with the counter

coolsamay coolsamay

2012/12/18

#
im getting this error message java.lang.NullPointerException at shark.hitafish(shark.java:85) at shark.eat(shark.java:54) at shark.act(shark.java:18) at greenfoot.core.Simulation.actActor(Simulation.java:565) at greenfoot.core.Simulation.runOneLoop(Simulation.java:523) at greenfoot.core.Simulation.runContent(Simulation.java:213) at greenfoot.core.Simulation.run(Simulation.java:203)
danpost danpost

2012/12/18

#
We need more than just the error message to go on. Please supply the 'hitafish' method in the 'shark' class, plus everything related to the counter (the class and any reference to the object in your world sub-class and in the shark class).
coolsamay coolsamay

2012/12/18

#
see my game -EAT THE FISH - open it in greenfoot
danpost danpost

2012/12/18

#
The problem is this: (1) you set up a field to hold a reference to the counter in the world class (ok) (2) you create a method to return the reference (ok) (3) you create a new counter object and add it to the world (ok) (4) you set the reference to the counter object to the object you created and added to the world (NEVER)
vonmeth vonmeth

2012/12/18

#
In your world class, you need to change this:
        Counter counter = new Counter();
        addObject(counter, 86, 29);
to this:
        theCounter = new Counter();
        addObject(theCounter, 86, 29);
You need to login to post a reply.