hi everyone im trying to use the method getObjects() and store them in a list but i keep getting a null pointer exception the program runs and compiles but as soon as the objects fade from the screen i get a null pointer exception ive attached my class code. i keep getting the error for the line" List<Sigma> sigmas = world.getObjects(Sigma.class);"
import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
import java.util.List;
/**
* A rotating Sigma on the visualizer
*
* @author Bryan Oritz
* @version 1.2
*/
public class Sigma extends Actor
{
int[] xPoints ={37,10,18,10,37};
int[] yPoints ={10,10,18,30,30};
int nPoints = 5;
/**
*
*/
public Sigma()
{
}
/**
* Sigma constructor
*/
public Sigma(int width, int height, Color color)
{
GreenfootImage image = new GreenfootImage(width, height);
image.setColor(color);
image.drawPolygon(xPoints, yPoints, nPoints);
setImage(image);
}
/**
* Act - do whatever the Stars wants to do. This method is called whenever
* the 'Act' or 'Run' button gets pressed in the environment.
*/
public void act()
{
int alpha = getImage().getTransparency();
if (alpha > 2)
{
getImage().setTransparency(alpha - 2);
}
else
{
getWorld().removeObject(this);
}
World world = getWorld();
List<Sigma> sigmas = world.getObjects(Sigma.class);
for (Sigma sigma : sigmas)
{
turn(5);
}
}
}
