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

2012/1/3

Compiler Warning: Unsafe operations

michiele michiele

2012/1/3

#
I keep getting a compiler warning that says: "Some input files use unsafe or unchecked operations". I did some research online and it seems to have something to do with defining a list wrong. However, I have defined my list as I saw in the greenfoot book, but I still get the warning. I have copied part of the code below. I commented out the line that is causing the warning. Can someone help me? I know this runs fine, but I don't want the warning message.
    private List<Tile> tiles;
           :
(code omitted here)
          :
    /**
     * Check for the end of the game when all tiles are in position.
     */
    public void act()
    {
        //tiles = getObjects(Tile.class);
      
        boolean allInPosition = true;

        for (Tile tile : tiles) 
        {
            if(!tile.inPosition()) {
                allInPosition = false;
            }
        }
        if(allInPosition) {
            Greenfoot.playSound("TwoBits.wav");
            Greenfoot.stop();
        }      
        
    }
darkmist255 darkmist255

2012/1/3

#
should it be something like this?
private List<Tile> tiles;

...

private void addedToWorld(world World)
{
tiles = getWorld().getObjects(Tile.class);
}
michiele michiele

2012/1/3

#
Well, I am in a world subclass so I can't use getWorld() or I get a compiler error... Anyone else have an idea?
davmac davmac

2012/1/3

#
I think it's a failure of Greenfoot to filter the warning, due to the warning message format being changed between Java 6 and Java 7 (i.e. I assume you get this warning when running Greenfoot with Java 7). See: http://bugs.bluej.org/trac/greenfoot/ticket/346 You can safely ignore the warning.
michiele michiele

2012/1/3

#
I like the idea that I can safely ignore the warning. However, I am running Java 6, update 29. Does that make a difference?
davmac davmac

2012/1/3

#
Does that make a difference?
Actually, the warning you get is slightly different to the one I linked to. However, you can still ignore it. Actually, with the current release of Greenfoot (2.1.2) that warning should be filtered. Are you perhaps using an older version? Regardless, the warning is just warning about a certain style of coding that is unavoidable when using Greenfoot - so you can ignore it.
michiele michiele

2012/1/4

#
That fixed it davmac. I was running 2.1.0. I upgraded to the current release of greenfoot and the warning is gone. I just don't like seeing the warning, especially since I teach an intro class. I don't want to worry about explaining it to them.
You need to login to post a reply.