samedi 9 mai 2015

NullPointerException Playing Sound Clip on Linux

So, I made this 2D platformer game using Java AWT /Swing a few years back. When i tested it then at windows environment everything worked fine, but now that I am trying to test it in linux it always gets NullPointerException while trying to play sound. Here's my SoundEffects Class which is used throughout the game to play various sounds, it works perfectly in windows, but caused NullPointerException when i try to play the "jump" sound in linux.

package galib.platformer.sound;

import java.io.File;
import java.net.URL;
import java.util.HashMap;

import javax.sound.sampled.AudioInputStream;
import javax.sound.sampled.AudioSystem;
import javax.sound.sampled.Clip;
import javax.swing.JOptionPane;

import resources.ResourceLoader;

public class SoundEffects {

public HashMap<String, Clip> audioClips;

public void init() {

    audioClips = new HashMap<String, Clip>();

    try {


         Clip backgroundSound = AudioSystem.getClip();

         backgroundSound.open(AudioSystem.getAudioInputStream(new File("res/resources/sounds/background.wav")));

         audioClips.put("background_music", backgroundSound);


        Clip jumpSound = AudioSystem.getClip();

        jumpSound.open(AudioSystem.getAudioInputStream(new File("res/resources/sounds/jump.wav")));

        audioClips.put("jump_sound", jumpSound);



        Clip gemsCollectSound = AudioSystem.getClip();

        gemsCollectSound.open(AudioSystem.getAudioInputStream(new File("res/resources/sounds/gems.wav")));

        audioClips.put("gems_sound", gemsCollectSound);



        Clip destroySound = AudioSystem.getClip();

        destroySound.open(AudioSystem.getAudioInputStream(new File("res/resources/sounds/destroy.wav")));

        audioClips.put("destroy_sound", destroySound);


    } catch (Exception e) {
        // TODO Auto-generated catch block

        e.printStackTrace();
    }

}

}

I am not sure why is it causing NullPointerException when i run it on linux. Any guesses ? Thanks in advance. :)

Aucun commentaire:

Enregistrer un commentaire