سؤال

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();
}
هل كانت مفيدة؟

المحلول

The file needs to be on your CLASSPATH. Is the CLASSPATH set appropriately in both applications?

نصائح أخرى

This error occurs when you try to create an AudioInputStream from a null URL.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top