So the idea here is to create an image switch when the object BODY touches the object BORDER. The object BORDER only changes images and remains changed until object BODY is no longer touching it. The strings are used in my world class to setup the images during spawning and essentially the soundfile is a sound that plays when the object BODY is overlapping object BORDER.
The error message is this:
java.lang.NullPointerException: Filename must not be null.
at greenfoot.GreenfootImage.loadFile(GreenfootImage.java:272)
at greenfoot.GreenfootImage.<init>(GreenfootImage.java:108)
at greenfoot.Actor.setImage(Actor.java:415)
at Border.switchImage(Border.java:61)
at Border.act(Border.java:36)
This is essentially pointing at the setImage(img2) and setImage(img1). Upon inspecting the object in the world, i can see that String img1 and img 2 are both null and I cannot understand how to fix this. Please help as I am only a beginner.
WITHIN THE BORDER ACTOR
public Border(String soundFile, String img1, String img2)
{
sound = soundFile;
touchingBody = false;
isDown = false;
img1 = ("Block1.png");
img2 = ("Block2.fw.png");
}
/**
* Constantly Running all methods; includes keyboard check method
*/
public void act()
{
checkBody();
switchImage();
}
public void checkBody()
{
if (getOneIntersectingObject(Body.class) == null)
{
touchingBody = false;
}
else
{
touchingBody = true;
}
}
public void switchImage()
{
if (touchingBody && !isDown)
{
setImage(img2);
isDown = true;
//play();
}
if (!touchingBody && isDown)
{
isDown = false;
setImage(img1);
}
}

