if(isTouching(knife.class))
{
knife c = (knife) getOneIntersectingObject(knife.class);
setLocation(c.getX(),c.getY());
}
but whenever it touches the knife the bear stops moving
and if i trying putting the same code in the knife this error comes
at greenfoot.core.Simulation.runContent(Simulation.java:193)
at greenfoot.core.Simulation.run(Simulation.java:183)
java.lang.NullPointerException
at knife.act(knife.java:20)
at greenfoot.core.Simulation.actActor(Simulation.java:567)
at greenfoot.core.Simulation.runOneLoop(Simulation.java:530)
at greenfoot.core.Simulation.runContent(Simulation.java:193)
at greenfoot.core.Simulation.run(Simulation.java:183)
Please post the full code of the knife class so that I can see where the exception occurs.
PS: By convention class names in java are written in CamelCase, meaning they start with a upper case letter
knife c = getOneIntersectingObject(knife.class);
if (c != null) setLocation(c.getX(), c.getY());
Remove all attempted codes in the knife class.
However, the player will still stop because you are telling it to stay where the knife is (assuming the knife does not move).