我不能讓我的代碼編譯,我甚至複製從這裏GitHub的代碼是代碼不被編譯[headintojava]
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錯誤:class ... expected。
我看到的主要錯誤是
"cannot access Midievent...bad source file .\MidiEvent.java.....file does not contain class MidiEvent....Please remove or make sure it appears in the correct subdirectory of the sourcepath
還有什麼問題呢?我讀使用相同的代碼的其他人沒有問題
這可能會有所幫助:http://stackoverflow.com/questions/12117680/java-package-does-not-exist-and-bad-source-file – Andrew
omg我找到了我自己的答案。吸收每個人。 ..事實證明,我實際上有一個名爲MidiEvent的文件夾> gallly
如果你想要硬核,並從命令行執行所有操作,那麼這是一個非常有用的鏈接。我會使用IDE。 – Andrew