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

2019/12/18

java.util.List<java.lang.Object> cannot be converted to java.util.List<greenfoot.Actor>

Cool Cool

2019/12/18

#
Hello I got a problem with Greenfoot: in line 3 of my code there is the error from the title and I don't know how to fix it... it says that the error is the "null"! thanks for the help
1
2
3
4
5
6
7
8
9
10
11
12
private void explodeOthers()
    {       
        List<Actor> actors = (List<Actor>) getIntersectingObjects(null);       
        for (Actor a : actors)
        {
            if( ! (a instanceof Explosion))
            {
                getWorld().addObject(new Explosion(), a.getX(), a.getY());
                getWorld().removeObject(a);
            }
        }
    }
danpost danpost

2019/12/18

#
You could try the following for line 3:
1
List<Actor> actors = (List<Actor>) getIntersectingObjects(Actor.class);
If that does not work, start with:
1
2
3
4
for (Object obj : getIntersectingObjects(null))
{
    Actor a = (Actor)obj;
    // etc.
You need to login to post a reply.