I have a countdown, that makes a sound when it hits a number, it works fine, until i actually run the program where it comes up with an error message:
java.lang.IllegalArgumentException: Could not open sound file: three.mp3
at greenfoot.sound.SoundExceptionHandler.handleIOException(SoundExceptionHandler.java:67)
at greenfoot.sound.SoundFactory.createSound(SoundFactory.java:120)
at greenfoot.Greenfoot.playSound(Greenfoot.java:163)
at Countdown.Countdown3(Countdown.java:37)
at Countdown.act(Countdown.java:29)
at greenfoot.core.Simulation.actActor(Simulation.java:604)
at greenfoot.core.Simulation.runOneLoop(Simulation.java:562)
at greenfoot.core.Simulation.runContent(Simulation.java:221)
at greenfoot.core.Simulation.run(Simulation.java:211)
Caused by: java.io.FileNotFoundException: Could not find file: three.mp3
at greenfoot.util.GreenfootUtil.getURL(GreenfootUtil.java:554)
at greenfoot.sound.SoundFactory.createSound(SoundFactory.java:99)
... 7 more
This is my code:
import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
/**
* Write a description of class Countdown here.
*
* @author (your name)
* @version (a version number or a date)
*/
public class Countdown extends Actor
{
private GreenfootImage Countdown3 = new GreenfootImage("Countdown3.png");
private GreenfootImage Countdown2 = new GreenfootImage("Countdown2.png");
private GreenfootImage Countdown1 = new GreenfootImage("Countdown1.png");
private GreenfootImage CountdownGo = new GreenfootImage("CountdownGo.png");
private int countdowntimer;
private boolean countDownFinished;
public boolean isCountDownFinished() {
return countDownFinished;
}
/**
* Act - do whatever the Countdown wants to do. This method is called whenever
* the 'Act' or 'Run' button gets pressed in the environment.
*/
public void act()
{
Countdown3();
}
public void Countdown3()
{
if(countdowntimer > 62)
{
Countdown2();
Greenfoot.playSound("three.mp3");
return;
}
else
{
countdowntimer++;
}
}
public void Countdown2()
{
setImage(Countdown2);
if(countdowntimer > 124)
{
Countdown1();
Greenfoot.playSound("two.mp3");
return;
}
else
{
countdowntimer++;
}
}
public void Countdown1()
{
setImage(Countdown1);
if(countdowntimer > 186)
{
CountdownGo();
Greenfoot.playSound("one.mp3");
countDownFinished = true;
return;
}
else
{
countdowntimer++;
}
}
public void CountdownGo()
{
setImage(CountdownGo);
if(countdowntimer > 248)
{
Greenfoot.playSound("Go.mp3");
World world;
world=getWorld();
world.removeObject(this);
}
else
{
countdowntimer++;
}
}
}
