Everything is correct with it. It is called identically to the previous call, except with a class that extends Critter. Critter extends Actor, so it should all work. It just doesn't for some reason.
Perhaps add this?
import info.gridworld.actor.FunkyCritter;
That should throw a compilation exception. Assuming I'm right in thinking he's using
this api, then there's no such thing as FunkyCritter in the info.gridworld.actor package. He would have had to define it himself in a local package.
All the same, change the import to
import info.gridworld.actor.*
That imports everything in that package. There are exactly six things in that particular package. Just import it all to keep things clean. You'll probably need all of them anyway. Besides, it's a sanity check in itself.
I think that error is saying that it can't find a method in ActorWorld called add that takes in a type FunkyCritter as a parameter. The most reasonable cause would be that something is going wrong with inheritance. It should be smart enough to implicitly cast your FunkyCritter to an Actor, but it wouldn't hurt to do the cast explicitly as a sanity check. Otherwise it's saying it can't find the FunkyCritter class. It's safe to assume that FunkyCritter extends Critter, is in the same package as the class containing the main method, you have your classpaths set correctly, and everything has been saved, right?
Perhaps add this?
import info.gridworld.actor.FunkyCritter;
The two classes are indeed in the same package. I can do this:
FunkyCritter c = new FunkyCritter();
world.add(c);
But, I get the same error on world.add(c);. I even attempted casting it to an Actor, but then I got an error about the cast. I don't remember the exact error message, and the code is on a different computer, so I can't tell you exactly what it said, but it was something along the lines of invalid cast.
As a sanity check, I made sure that FunkyCritter does indeed extend Critter.
That first statement is contradictory. You wouldn't be importing anything from this jar file or packages if you were working from within the same package. You either imported the existing code and started modifying things from there or you imported the jar file and started modifying from your own package. I've been assuming you're importing the jar file and that you have the StuffRunner and FunkyCritter classes in the same package separate from the gridworld packages.
The second statement is what interests me. If you got a ClassCastException while trying to cast it from a FunkyCritter to an Actor, something is wrong. Thirty-second sanity check; create an ordinary Critter and cast it to an Actor. If that fails, something is horribly wrong. Otherwise, there's something wrong with the FunkyCritter class definition.
I've never used
gridworld before, but it's apparently freely available. Assuming the gridworld.jar is in your class path, this should work. It's working fine in my test environment, anyway. Here's my test environment. It looks more or less like yours does, right?
package gridworld.test;
import info.gridworld.actor.*;
public class Main {
public static void main(String[] args) {
ActorWorld world = new ActorWorld();
world.add(new Rock());
world.add(new FunkyCritter());
System.out.println("success");
}
}
package gridworld.test;
import info.gridworld.actor.Critter;
public class FunkyCritter extends Critter {
public FunkyCritter() {
super();
}
public void act() {
// do something...
}
}
Beyond that, I'd need to actually see your FunkyCritter class. I'm running out of obvious errors.