so i have made a game where there is a mute button on the top left however if you press the mute button on another screen it says "java.lang.ClassCastException: class selectCharacter cannot be cast to class Main_Menu (selectCharacter and Main_Menu are in unnamed module of loader java.net.URLClassLoader @38dacfba)
at Music.act(Music.java:25)
at greenfoot.core.Simulation.actActor(Simulation.java:567)
at greenfoot.core.Simulation.runOneLoop(Simulation.java:530)
at greenfoot.core.Simulation.runContent(Simulation.java:193)
at greenfoot.core.Simulation.run(Simulation.java:183)"
this is my current codethen i have the next line which is from the mute button.
private GreenfootSound backgroundMusic = new GreenfootSound("Colours.wav");
public void unmute()
{
backgroundMusic.playLoop();
}
public void mute()
{
backgroundMusic.pause();
}private GreenfootImage[] images = {new GreenfootImage("Music.png"), new GreenfootImage("Mute.png")};
public Music()
{
setImage(images[0]);
}
public void act()
{
if (Greenfoot.mousePressed(this))
{
if (getImage() == images[0])
{
setImage(images[1]);
((Main_Menu) getWorld()).mute();
}
else
{
setImage(images[0]);
((Main_Menu) getWorld()).unmute();
}
}
}

