MidiSystem.getSequencer()在编译时给出错误 - 找不到符号

时间:2015-02-13 05:17:52

标签: java

import javax.sound.midi.*;


public class MiniMiniMusicApp
{
    public static void main(String[] args)
    {
        MiniMiniMusicApp mini = new MiniMiniMusicApp();
        mini.play();
    }//close main

    public void play()
    {
        try
        {
            Sequencer player = new MidiSystem.getSequencer();
            player.open();

            Sequence seq = new Sequence(Sequence.PPQ, 4);

            Track track = seq.createTrack();

            ShortMessage a = new ShortMessage();
            a.setMessage(144, 1, 44, 100);
            MidiEvent noteOn = new MidiEvent(a,1);
            track.add(noteOn);

            ShortMessage b = new ShortMessage();
            b.setMessage(128, 1, 44, 100);
            MidiEvent noteOff = new MidiEvent(b, 16);
            track.add(noteOff);

            player.setSequence(seq);

            player.start();
        }catch(Exception ex)
        {
            ex.printStackTrace();
        }
    }//close play
}//close class

我有1.8版本。当我尝试编译这个时,我得到了“找不到符号”#39;来自MidiSystem.getSequencer()行的错误。我知道它在那里,因为我刚刚检查了在线API并且我有最新版本。我不确定我在这里做错了什么。

1 个答案:

答案 0 :(得分:0)

Sequencer player = new MidiSystem.getSequencer();

从上面的行中移除new关键字, 它用于从类创建新的Object。我相信MidiSystem.getSequencer()会返回Sequecer对象

所以它应该是

Sequencer player = MidiSystem.getSequencer();