我无法编译我的代码,我什至从 github 复制了代码在这里
import javax.sound.midi.*;
public class MiniMusicPlayer1 {
public static void main(String[] args) {
try {
Sequencer sequencer = MidiSystem.getSequencer();
sequencer.open();
Sequence seq = new Sequence(Sequence.PPQ, 4);
Track track = seq.createTrack();
for(int i = 5; i < 61; i += 4) {
track.add(makeEvent(144,1,i,100,i));
track.add(makeEvent(128,1,i,100,i + 2));
}
sequencer.setSequence(seq);
sequencer.setTempoInBPM(220);
sequencer.start();
} catch(Exception ex) {
ex.printStackTrace();
}
}
public static MidiEvent makeEvent(int comd, int chan, int one, int two, int tick) {
MidiEvent event = null;
try {
ShortMessage a = new ShortMessage();
a.setMessage(comd, chan, one, two);
event = new MidiEvent(a, tick);
} catch(Exception e) {
}
return event;
}
}
我输入javac MiniMusicPlayer1.java
,它给了我一些错误,都与 midievent 有关。第一个错误是 Midievent.java:1 error: class...expected。
我看到的主要错误是
“无法访问 Midievent...错误的源文件 .\MidiEvent.java .....文件不包含类 MidiEvent...。请删除或确保它出现在源路径的正确子目录中
问题可能是什么?我阅读其他人使用相同的代码没有问题