Alright so I've tried to do the exercise myself. I've followed the instructions as told and compare to the answer. It seems the code matches and while I compiled it the counter does not change every time I shot an asteroid. Please help.
Not working for me :(
Compiling works, no errors getting returned.
But if a shot hits an asteroid it says:
-------------------------------------------------------------------------------------
java.lang.NullPointerException
at Shot.hitAnAsteroid(Shot.java:58)
at Shot.act(Shot.java:34)
at greenfoot.core.Simulation.actActor(Simulation.java:594)
at greenfoot.core.Simulation.runOneLoop(Simulation.java:552)
at greenfoot.core.Simulation.runContent(Simulation.java:215)
at greenfoot.core.Simulation.run(Simulation.java:205)
--------------------------------------------------------------------------------------------------
private void hitAnAsteroid() {
Space spaceWorld = (Space) getWorld(); // get a reference to the world
XX Counter counter = spaceWorld.getCounter(); // get a reference to the counter XX
counter.bumpCount(5); }
--------------------------------------------------------------------------------------------------
that´s the code, the line marked with X´s is supposedly containing the error... but i dont get it
Any help appreciated :)
I guess you changed the code of the class. You added at least four lines of code. The original one works without errors. What did you change (for example in the act method)? It would probably be the best to open a new discussion with a link to this scenario instead.
i have a doubt i your tutorial
will it work or not
//in rocket.class
//globally
Counter counter; //i already added it in the world i.e. Counter counter=new Counter
addObject(counter,150,100)
//in hitByAsteriod() method
{
counter.bumpCount(5);
}
reply this one
i have a doubt in your tutorial
will it work or not
//in rocket.class
//globally
Counter counter; //i already added it in the world i.e. Counter counter=new Counter
addObject(counter,150,100)
//in hitByAsteriod() method of Rocket.class
{
counter.bumpCount(5);
}
2011/11/1
2012/5/20
2012/10/10
2012/11/15
2013/11/7
2014/3/22
2015/3/24
2015/4/8
2017/6/14
2017/6/14
2017/8/27
2017/8/27
2020/6/23
2020/6/23
2020/6/23