Reputation: 3548
I don't understand why I'm getting:
java.lang.NullPointerException
at com.sun.media.sound.StandardMidiFileReader.getSequence(Unknown Source)
at javax.sound.midi.MidiSystem.getSequence(Unknown Source)
at com.sun.media.sound.SoftMidiAudioFileReader.getAudioInputStream(Unknown Source)
at javax.sound.sampled.AudioSystem.getAudioInputStream(Unknown Source)
Even though the same code works in my another application. The file path is correct, the file is there. I'm clueless.
Relevant code before sound method:
String soundpath = "res/sound.au";
sound(soundpath);
Here's my sound method:
public static void sound(String path){
try {
AudioInputStream audio = AudioSystem.getAudioInputStream(SoundTest.class.getResource(path));
Clip clip = AudioSystem.getClip();
clip.open(audio);
clip.start();
} catch (Exception e) {
System.out.println("Might wanna check: " + path + "\n");
e.printStackTrace();
}
Upvotes: 0
Views: 1316
Reputation: 25220
This error occurs when you try to create an AudioInputStream from a null URL.
Upvotes: 0
Reputation: 33083
The file needs to be on your CLASSPATH
. Is the CLASSPATH
set appropriately in both applications?
Upvotes: 2