'Why isn't SoundFile.play not working processing 4

So I'm trying to play a simple sound file and it's not working. The specific code is

  if(key == 'r' || key == 'R') {
    file = new SoundFile(this, "track1.wav");
    file.play();
  }
  if(key == 't' || key == 'T') {
    file = new SoundFile(this, "track2.wav");
    file.play();
  }
  if(key == 'y' || key == 'Y') {
    file = new SoundFile(this, "track3.wav");
    file.play();
  }

It gives me this error

javax.sound.sampled.LineUnavailableException: line with format PCM_SIGNED 44100.0 Hz, 16 bit, stereo, 4 bytes/frame, little-endian not supported.
    at java.desktop/com.sun.media.sound.DirectAudioDevice$DirectDL.implOpen(DirectAudioDevice.java:484)
    at java.desktop/com.sun.media.sound.AbstractDataLine.open(AbstractDataLine.java:115)
    at com.jsyn.devices.javasound.JavaSoundAudioDevice$JavaSoundInputStream.start(Unknown Source)
    at com.jsyn.engine.SynthesisEngine$EngineThread.run(Unknown Source)
java.lang.NullPointerException: Cannot invoke "javax.sound.sampled.TargetDataLine.read(byte[], int, int)" because "this.line" is null
    at com.jsyn.devices.javasound.JavaSoundAudioDevice$JavaSoundInputStream.read(Unknown Source)
    at com.jsyn.devices.javasound.JavaSoundAudioDevice$JavaSoundInputStream.read(Unknown Source)
    at com.jsyn.engine.SynthesisEngine$EngineThread.run(Unknown Source)
java.lang.RuntimeException: AudioInput stop attempted when no line created.
    at com.jsyn.devices.javasound.JavaSoundAudioDevice$JavaSoundInputStream.stop(Unknown Source)
    at com.jsyn.engine.SynthesisEngine$EngineThread.run(Unknown Source)


Solution 1:[1]

i suggest to add this sound files under res folder. in my project, I created folder named "raw" under "res folde" with these files in it, sound.mp3 and for playing it, i used this

mediaPlayer = MediaPlayer.create(SCREEN_NAME.this,R.track1);
                                    mediaPlayer.start();

edit: and i created this variable

    private MediaPlayer mediaPlayer;

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Dharman