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

2015/3/10

How to set values?

1
2
RagingAsian RagingAsian

2015/3/12

#
Sorry not very good at explaining. I want to get my lives counter to add -1, or decrease 1, every time a greep has reached the end the the path which would be coordinates 599(x),140(y), but when it does there is a null pointer exception. I imported the counter btw. java.lang.NullPointerException at Greeps.movement(Greeps.java:93) at Small.act(Small.java:25) at greenfoot.core.Simulation.actActor(Simulation.java:568) at greenfoot.core.Simulation.runOneLoop(Simulation.java:526) at greenfoot.core.Simulation.runContent(Simulation.java:215) at greenfoot.core.Simulation.run(Simulation.java:205)
davmac davmac

2015/3/12

#
java.lang.NullPointerException at Greeps.movement(Greeps.java:93)
This is telling you that you are attempting to de-reference a null reference on line 93 of your Greeps class. First step: look at the line and see what might be null.
                    getWorld().removeObject(this);  
... the only thing on the left-hand-side of a dot operator is 'getWorld()', so that must be returning null. Which means: your object isn't in any world. Which probably means: your 'Small' subclass is removing 'this' instance from the world before it calls the 'movement' method. Probably, you should not call 'movement()' if you have removed the object from the world (i.e. change code in your 'Small' class so that it won't do this).
You need to login to post a reply.
1
2