我写了一个类来播放midi文件。我已经通过在自己的线程中运行它来测试这个类,它播放的是预期的歌曲,但它也会以红色显示警告:
May 21, 2014 12:55:03 PM java.util.prefs.WindowsPreferences <init>
WARNING: Could not open/create prefs root node Software\JavaSoft\Prefs at root 0x80000002. Windows RegCreateKeyEx(...) returned error code 5.
我的代码有效,但我想知道这个警告意味着什么,以及如何修复它。
public class MusicBox implements Runnable {
private Sequence midi;
private Sequencer sequencer;
private boolean playSong;
public MusicBox() {
try {
this.midi = MidiSystem.getSequence(new File("src//BennyHill.mid"));
this.sequencer = MidiSystem.getSequencer();
} catch (InvalidMidiDataException e) {
System.out.println("invalidMidiData exception in Music Box");
e.printStackTrace();
} catch (IOException e){
System.out.println("IO exception in Music Box");
e.printStackTrace();
} catch (MidiUnavailableException e) {
System.out.println("Midi Unavailable Exception in Music Box");
e.printStackTrace();
}
this.playSong = false;
}
@Override
public void run() {
try {
this.sequencer.open();
this.sequencer.setSequence(this.midi);
} catch (MidiUnavailableException e) {
System.out.println("MidiUnavailableException in play music (run)");
e.printStackTrace();
} catch (InvalidMidiDataException e) {
System.out.println("InvalidMidiDataException in play music (run)");
e.printStackTrace();
}
this.sequencer.start();
while(this.playSong){
try {
Thread.sleep(100);
} catch (InterruptedException e) {
//do nothing
}
}
this.sequencer.stop();
this.sequencer.close();
}
}