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

2020/3/19

Problem when resetting game

CodesForFun CodesForFun

2020/3/19

#
Exception in thread "SoundStream:file:/C:/Users/villa/OneDrive/Documents/Bomb%20Bouncers/sounds/Field4.mp3" Exception in thread "SoundStream:file:/C:/Users/villa/OneDrive/Documents/Bomb%20Bouncers/sounds/Field4.mp3" java.lang.ArrayIndexOutOfBoundsException: Index 580 out of bounds for length 580 at javazoom.jl.decoder.LayerIIIDecoder.huffman_decode(LayerIIIDecoder.java:795) at javazoom.jl.decoder.LayerIIIDecoder.decode(LayerIIIDecoder.java:278) at javazoom.jl.decoder.LayerIIIDecoder.decodeFrame(LayerIIIDecoder.java:219) at javazoom.jl.decoder.Decoder.decodeFrame(Decoder.java:147) at greenfoot.sound.Mp3AudioInputStream.read(Mp3AudioInputStream.java:230) at greenfoot.sound.SoundStream.run(SoundStream.java:255) at java.base/java.lang.Thread.run(Thread.java:834) I keep getting this error whenever I run the title screen after playing a level in my game. Whenever I reset after getting a game over, this happens. I don't know why. Here's the code for the title screen:
public class titleScreen extends World
{
    public static final GreenfootSound backgroundMusic = new GreenfootSound("Field4.mp3");

    /**
     * Constructor for objects of class titleScreen.
     * 
     */
    public titleScreen()
    {    
        // Create a new world with 600x400 cells with a cell size of 1x1 pixels.
        super(600, 400, 1);
        prepare();
        backgroundMusic.playLoop();
        Greenfoot.start();
    }

    /**
     * Prepare the world for the start of the program.
     * That is: create the initial objects and add them to the world.
     */
    private void prepare()
    {
        Play play = new Play();
        addObject(play,205,126);
        Help help = new Help();
        addObject(help,368,217);
        Credits credits = new Credits();
        addObject(credits,205,293);
    }
}
EDIT: I realized that some people may ask for the level code, so here it is, just in case it narrows it down, as well as the game over code:
public class firstLevel extends World
{
    /**
     * Constructor for objects of class MyWorld.
     * 
     */
    public int score;
    public int i;
    public int scoreTick;
    public int spawnTimerSpeedUp;
    public int spawnTimerSpeedDown;
    public int spawnTimerBallSpeedUp;
    public int spawnTimerBallSpeedDown;
    public int spawnTimerScoreUp;
    public int spawnTimerScoreDown;
    public int spawnTimerReverseControls;
    public int spawnTimerTransparentBall;
    public int spawnTimerFog;
    public int spawnTimerEMP;
    private int timerThingSpeedUp = getRandomNumber(755, 1000);
    private int timerThingSpeedDown = getRandomNumber(768, 1100);
    private int timerThingBallSpeedUp = getRandomNumber(843, 1231);
    private int timerThingBallSpeedDown = getRandomNumber(752, 1500);
    private int timerThingScoreUp = getRandomNumber(600, 1200);
    private int timerThingScoreDown = getRandomNumber(832, 1311);
    private int timerThingReverseControls = getRandomNumber(713, 912);
    private int timerThingTransparentBall = getRandomNumber(900, 1321);
    private int timerThingFog = getRandomNumber(1200, 1542);
    private int timerThingEMP = getRandomNumber(1000, 1329);
    private Paddle thePaddle;
    private Ball theBall;
    private Fog theFog = new Fog();
    private EMPGrenade theEMP = new EMPGrenade();
    private EMPBlast theBlast = new EMPBlast();
    private Counter scoreCounter;
    public static final GreenfootSound backgroundMusic = new GreenfootSound("03_Otherworldly_Corridor.mp3");
    public firstLevel()
    {    
        // Create a new world with 600x400 cells with a cell size of 1x1 pixels.
        super(600, 400, 1);
        setPaintOrder(Counter.class, Fog.class, EMPBlast.class, EMPGrenade.class, Paddle.class, Ball.class, PaddleSpeedUp.class, PaddleSpeedDown.class, BallSpeedUp.class, BallSpeedDown.class, PlusFivePoints.class, MinusFivePoints.class, ReverseControls.class, TransparentBall.class, FogBall.class, EMPBallDrop.class);
        scoreCounter = new Counter("Score: ");
        addObject(scoreCounter, 300, 20);
        backgroundMusic.playLoop();
        prepare();
    }

    public void act(){
        randomlySpawnSpeedUp();
        randomlySpawnSpeedDown();
        randomlySpawnBallSpeedUp();
        randomlySpawnBallSpeedDown();
        randomlySpawnScoreUp();
        randomlySpawnScoreDown();
        randomlySpawnReverseControls();
        randomlySpawnTransparentBall();
        randomlySpawnFog();
        randomlySpawnEMP();
        scoreTick++;
        if(scoreTick%60==0){
            score++;
        }
        scoreCounter.setValue(score);
    }

    /**
     * Prepare the world for the start of the program.
     * That is: create the initial objects and add them to the world.
     */
    private void prepare()
    {
        theBall = new Ball();
        addObject(theBall,300,144);
        thePaddle = new Paddle();
        addObject(thePaddle,300,337);
        Ground ground = new Ground();
        addObject(ground,300,399);
    }

    public void randomlySpawnSpeedUp(){
        spawnTimerSpeedUp = (spawnTimerSpeedUp+1)%timerThingSpeedUp; // repeat every 10 seconds (about)
        if (spawnTimerSpeedUp == 0) // at each timer reset
        {
            timerThingSpeedUp = getRandomNumber(755, 1000);
            addObject(new PaddleSpeedUp(), Greenfoot.getRandomNumber(600), Greenfoot.getRandomNumber(290));
        }
    }

    public void randomlySpawnSpeedDown(){
        spawnTimerSpeedDown = (spawnTimerSpeedDown+1)%timerThingSpeedDown; // repeat every 10 seconds (about)
        if (spawnTimerSpeedDown == 0) // at each timer reset
        {
            timerThingSpeedDown = getRandomNumber(768, 1100);
            addObject(new PaddleSpeedDown(), Greenfoot.getRandomNumber(600), Greenfoot.getRandomNumber(290));
        }
    }

    public void randomlySpawnBallSpeedUp(){
        spawnTimerBallSpeedUp = (spawnTimerBallSpeedUp+1)%timerThingBallSpeedUp; // repeat every 10 seconds (about)
        if (spawnTimerBallSpeedUp == 0) // at each timer reset
        {
            timerThingBallSpeedUp = getRandomNumber(843, 1231);
            addObject(new BallSpeedUp(), Greenfoot.getRandomNumber(600), Greenfoot.getRandomNumber(290));
        }
    }

    public void randomlySpawnBallSpeedDown(){
        spawnTimerBallSpeedDown = (spawnTimerBallSpeedDown+1)%timerThingBallSpeedDown; // repeat every 10 seconds (about)
        if (spawnTimerBallSpeedDown == 0) // at each timer reset
        {
            timerThingBallSpeedDown = getRandomNumber(752, 1500);
            addObject(new BallSpeedDown(), Greenfoot.getRandomNumber(600), Greenfoot.getRandomNumber(290));
        }
    }

    public void randomlySpawnScoreUp(){
        spawnTimerScoreUp = (spawnTimerScoreUp+1)%timerThingScoreUp; // repeat every 10 seconds (about)
        if (spawnTimerScoreUp == 0) // at each timer reset
        {
            timerThingScoreUp = getRandomNumber(600, 1200);
            addObject(new PlusFivePoints(), Greenfoot.getRandomNumber(600), Greenfoot.getRandomNumber(290));
        }
    }

    public void randomlySpawnScoreDown(){
        spawnTimerScoreUp = (spawnTimerScoreUp+1)%timerThingScoreUp; // repeat every 10 seconds (about)
        if (spawnTimerScoreUp == 0) // at each timer reset
        {
            timerThingScoreUp = getRandomNumber(832, 1311);
            addObject(new PlusFivePoints(), Greenfoot.getRandomNumber(600), Greenfoot.getRandomNumber(290));
        }
    }

    public void randomlySpawnReverseControls(){
        spawnTimerReverseControls = (spawnTimerReverseControls+1)%timerThingReverseControls; // repeat every 10 seconds (about)
        if (spawnTimerReverseControls == 0) // at each timer reset
        {
            timerThingReverseControls = getRandomNumber(713, 912);
            addObject(new ReverseControls(), Greenfoot.getRandomNumber(600), Greenfoot.getRandomNumber(290));
        }
    }

    public void randomlySpawnTransparentBall(){
        spawnTimerTransparentBall = (spawnTimerTransparentBall+1)%timerThingTransparentBall; // repeat every 10 seconds (about)
        if (spawnTimerTransparentBall == 0) // at each timer reset
        {
            timerThingTransparentBall = getRandomNumber(900, 1321);
            addObject(new TransparentBall(), Greenfoot.getRandomNumber(600), Greenfoot.getRandomNumber(290));
        }
    }

    public void randomlySpawnFog(){
        spawnTimerFog = (spawnTimerFog+1)%timerThingFog; // repeat every 10 seconds (about)
        if (spawnTimerFog == 0) // at each timer reset
        {
            timerThingFog = getRandomNumber(900, 1321);
            addObject(new FogBall(), Greenfoot.getRandomNumber(600), Greenfoot.getRandomNumber(290));
        }
    }

    public void randomlySpawnEMP(){
        spawnTimerEMP = (spawnTimerEMP+1)%timerThingEMP; // repeat every 10 seconds (about)
        if (spawnTimerEMP == 0) // at each timer reset
        {
            timerThingEMP = getRandomNumber(1000, 1329);
            addObject(new EMPBallDrop(), Greenfoot.getRandomNumber(600), Greenfoot.getRandomNumber(290));
        }
    }

    public void showFog(){
        addObject(theFog,300,getRandomNumber(110,227));
    }

    public void callGrenade(){
        addObject(theEMP,theBall.x,theBall.y);
    }

    public void callBlast(){
        addObject(theBlast,empX(),empY());
    }

    public int getRandomNumber(int start, int end){
        int normal = Greenfoot.getRandomNumber(end-start+1);
        return normal+start;
    }

    public Paddle getPaddle(){
        return thePaddle;
    }

    public Ball getBall(){
        return theBall;
    }

    public Counter getCounter(){
        return scoreCounter;
    }

    public Fog getFog(){
        return theFog;
    }

    public EMPGrenade getEMP(){
        return theEMP;
    }

    public int empX(){
        return theEMP.x;
    }

    public int empY(){
        return theEMP.y;
    }

    public EMPBlast getBlast(){
        return theBlast;
    }
    public int getScore(){
        return score;
    }
}
public class GameOver extends World
{
    GreenfootSound explosion = new GreenfootSound("Explosion+11.mp3");
    /**
     * Constructor for objects of class GameOver.
     * 
     */
    public GameOver()
    {    
        // Create a new world with 600x400 cells with a cell size of 1x1 pixels.
        super(600, 400, 1);
        explosion.play();
        Greenfoot.stop();
    }
}
danpost danpost

2020/3/19

#
It appears your mp3 file has information data tagged to it. The sound file will need to be re-saved without the extraneous information to run in greenfoot.
CodesForFun CodesForFun

2020/3/19

#
danpost wrote...
It appears your mp3 file has information data tagged to it. The sound file will need to be re-saved without the extraneous information to run in greenfoot.
Okay, so how do I do that? I'm kind of new to Greenfoot.
danpost danpost

2020/3/19

#
CodesForFun wrote...
so how do I do that? I'm kind of new to Greenfoot.
This is not a greenfoot thing. You need a sound file editor for this.
CodesForFun CodesForFun

2020/3/19

#
danpost wrote...
CodesForFun wrote...
so how do I do that? I'm kind of new to Greenfoot.
This is not a greenfoot thing. You need a sound file editor for this.
Oh, okay. EDIT: I have audacity, does anyone know how to remove the extraneous data with it?
CodesForFun CodesForFun

2020/3/19

#
I have tried removing all the data that I know of in Audacity, and even by going into the properties and deleting all the info there, but I still keep getting the error, even when I use a different song.
danpost danpost

2020/3/19

#
CodesForFun wrote...
I have tried removing all the data that I know of in Audacity, and even by going into the properties and deleting all the info there, but I still keep getting the error, even when I use a different song.
Try exporting them as wav files.
CodesForFun CodesForFun

2020/3/19

#
danpost wrote...
CodesForFun wrote...
I have tried removing all the data that I know of in Audacity, and even by going into the properties and deleting all the info there, but I still keep getting the error, even when I use a different song.
Try exporting them as wav files.
It now throws a different error: Caused by: java.io.IOException: Stream closed at java.base/java.io.BufferedInputStream.getInIfOpen(BufferedInputStream.java:165) at java.base/java.io.BufferedInputStream.available(BufferedInputStream.java:416) at java.desktop/javax.sound.sampled.AudioInputStream.available(AudioInputStream.java:390) at greenfoot.sound.JavaAudioInputStream.available(JavaAudioInputStream.java:98) at greenfoot.sound.SoundStream.run(SoundStream.java:252) ... 1 more (it doesn't specify the one more)
danpost danpost

2020/3/19

#
CodesForFun wrote...
It now throws a different error: << Error Trace Omitted >>
Sorry -- not familiar with that one. Maybe you still have the file opened in audacity??
CodesForFun CodesForFun

2020/3/19

#
After exiting Audacity, yet another error popped up: java.lang.IllegalArgumentException: Could not open sound file: file:/C:/Users/villa/OneDrive/Documents/Bomb%20Bouncers/sounds/Field4.wav at greenfoot.sound.SoundExceptionHandler.handleIOException(SoundExceptionHandler.java:66) at greenfoot.sound.SoundStream.run(SoundStream.java:374) at java.base/java.lang.Thread.run(Thread.java:834) Caused by: java.io.IOException: Stream closed at java.base/java.io.BufferedInputStream.getBufIfOpen(BufferedInputStream.java:176) at java.base/java.io.BufferedInputStream.read(BufferedInputStream.java:342) at java.desktop/javax.sound.sampled.AudioInputStream.read(AudioInputStream.java:287) at greenfoot.sound.JavaAudioInputStream.read(JavaAudioInputStream.java:152) at greenfoot.sound.SoundStream.run(SoundStream.java:302) ... 1 more What confuses me is that it says it can't open the sound file - yet I can still hear the song play.
danpost danpost

2020/3/19

#
Sorry, but this is getting to be unfamiliar territory for me. Only suggestion I could make is to upload the scenario with source to allow others to possibly work out a fix. What kind of system are you running? (Windows, Mac, ...)
You need to login to post a reply.