标签:
以下是我的程序(取自好headfirst Java):
1 import javax.sound.midi.*; 2 3 public class MiniMiniMusicApp { 4 public static void main(String[] args) { 5 MiniMiniMusicApp mini = new MiniMiniMusicApp(); 6 mini.play(); 7 } 8 public void play() { 9 try { 10 Sequencer player = MidiSystem.getSequencer(); 11 player.open(); 12 13 Sequence seq = new Sequence(Sequence.PPQ, 4); 14 15 Track track = seq.createTrack(); 16 17 ShortMessage a = new ShortMessage(); 18 a.setMessage(144, 1, 44, 100); 19 MidiEvent noteOn = new MidiEvent(a, 1); 20 track.add(noteOn); 21 22 ShortMessage b = new ShortMessage(); 23 b.setMessage(128, 1, 44, 100); 24 MidiEvent noteOff = new MidiEvent(b, 16); 25 track.add(noteOff); 26 27 player.setSequence(seq); 28 29 player.start(); 30 } catch (Exception ex) { 31 ex.printStackTrace(); 32 } 33 34 } 35 }
在win8.1出现的错误信息如下:
WARNING: Could not open/create prefs root node Software\JavaSoft\Prefs at root 0
x80000002. Windows RegCreateKeyEx(...) returned error code 5.
解决方法如下:
Step1:搜索并运行regedit.exe
Step2: 进入HKEY_LOCAL_MACHINE\SOFTWARE\JavaSoft,右击JavaSoft目录,选择新建->项(key),命名为Prefs
Step3: 重新编译即可。
标签:
原文地址:http://www.cnblogs.com/lzpadmin/p/4445251.html