得到一个不寻常的错误: - 此处不允许使用'void'类型
import javax.sound.midi.*;
public class MiniMusicPlayer1 {
public static void main(String[] args) {
try {
Sequencer player = MidiSystem.getSequencer();
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));
}
player.setSequence(seq);
player.setTempoInBPM(220);
player.start();
} catch (Exception ex) {
System.out.println(ex.printStackTrace());
}
}
public static MidiEvent makeEvent(int comd, int ch, int note, int vel,
int tick) {
MidiEvent event = null;
try
{
ShortMessage a = new ShortMessage();
a.setMessage(comd, ch, note, vel);
event = new MidiEvent(a,tick);
}
catch(Exception e)
{
System.out.println(e.getMessage());
}
return event;
}
ankit @ battlestar:/ home / mount_150 / Java $ javac MiniMusicPlayer1.java MiniMusicPlayer1.java:21:错误:此处不允许使用'void'类型 的System.out.println(ex.printStackTrace()); ^
请帮忙。
答案 0 :(得分:10)
您正在调用printStackTrace
并将其无效结果“传递”到println
。
println
需要打印一些内容:您只需要ex.printStackTrace()
。