我不明白为什么我会得到:
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)
即使相同的代码在我的另一个应用程序中工作。文件路径正确,文件就在那里。我一无所知。
sound方法前的相关代码:
String soundpath = "res/sound.au";
sound(soundpath);
这是我的声音方法:
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();
}