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

2017/10/22

SetVolume() creates NullPointException

LuizAntonio LuizAntonio

2017/10/22

#
In my game, when the enemy dies, it plays a death sound correctly, but when I'm trying to play a sound when my character dies, it doesn't work. The win and lose menu music doesn't work either. What is causing the problem? My guess is a Greenfoot problem with sound files.
    public GanhouW()
    {    
        super(900, 650, 1);     
        prepare();
        GreenfootSound win = new GreenfootSound("ganhou.wav");
        //ganhou.stop();
        win.setVolume(60); 
        win.play();
    }

and my error is this one: java.lang.NullPointerException at greenfoot.sound.SoundStream.setVolume(SoundStream.java:461) at greenfoot.GreenfootSound.setVolume(GreenfootSound.java:129) at GanhouW.<init>(GanhouW.java:21) at UmJogadorW.act(UmJogadorW.java:180) at greenfoot.core.Simulation.actWorld(Simulation.java:610) at greenfoot.core.Simulation.runOneLoop(Simulation.java:545) at greenfoot.core.Simulation.runContent(Simulation.java:221) at greenfoot.core.Simulation.run(Simulation.java:211)
danpost danpost

2017/10/23

#
LuizAntonio wrote...
when I'm trying to play a sound when my character dies, it doesn't work. The win and lose menu music doesn't work either. What is causing the problem
It appears to be a problem with setting the volume. Try just removing line 7 above.
LuizAntonio LuizAntonio

2017/10/24

#
danpost wrote...
It appears to be a problem with setting the volume. Try just removing line 7 above.
Removed line 7, the error went away but the sound didn't played at all. Is there some problems with sound on Greenfoot? Maybe I should find another file to replace it?
danpost danpost

2017/10/24

#
LuizAntonio wrote...
Maybe I should find another file to replace it?
You could try . If your enemy death sound is from a "wav" type file, then the only thing I could imagine is that the one sound file is not properly formatted or corrupted. Otherwise, you might try reformatting it to the same type as the enemy death sound file.
LuizAntonio LuizAntonio

2017/10/24

#
danpost wrote...
You could try . If your enemy death sound is from a "wav" type file, then the only thing I could imagine is that the one sound file is not properly formatted or corrupted. Otherwise, you might try reformatting it to the same type as the enemy death sound file.
You were right. I downloaded a WAV to MP3 converter and used the new MP3 file and it worked successfully. Sorry to waste your time, I should have guessed this was the problem all along. Thank you.
You need to login to post a reply.