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

2017/1/24

incompatible types: java.lang.Object cannot be converted to greenfoot.Actor

MrsWarren MrsWarren

2017/1/24

#
in the "little crab" scenario (Ch 2 of Greenfoot textbook) there are errors in the Animal class code on my computer. Errors are indicated in the parameters of "getOneObjectAtOffset(0, 0, clss);" in both methods below. The program will not compile. How do I fix this? /** * Return true if we can see an object of class 'clss' right where we are. * False if there is no such object here. */ public boolean canSee(Class clss) { Actor actor = getOneObjectAtOffset(0, 0, clss); return actor != null; } /** * Try to eat an object of class 'clss'. This is only successful if there * is such an object where we currently are. Otherwise this method does * nothing. */ public void eat(Class clss) { Actor actor = getOneObjectAtOffset(0, 0, clss); if(actor != null) { getWorld().removeObject(actor); } }
danpost danpost

2017/1/24

#
Please show the code of the subclass that extends the Animal class that is producing this error.
You need to login to post a reply.