Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Head First : MiniMiniMusicApp

 
divya sharma
Ranch Hand
Posts: 87
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,

I am running following code from "Head First" chap-11
Code :

import javax.sound.midi.*;

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

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

Sequencer seq = new Sequencer(Sequencer,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();
a.setMessage(128,1,44,100);
MidiEvent noteOff = new MidiEvent(a,16);
track.add(noteOff);

player.setSequence(seq);

player.start();
}
catch(Exception ex)
{
ex.printStackTrace();
}
}


}

But when I am running it !!! Following error is displayed. Please help me to resolve there error.

D:\JavaProg\head first\chap-11\MiniMiniMusicApp.java:18: cannot resolve symbol
symbol : variable Sequencer
location: class MiniMiniMusicApp
Sequencer seq = new Sequencer(Sequencer,PPQ,4);
^
D:\JavaProg\head first\chap-11\MiniMiniMusicApp.java:18: cannot resolve symbol
symbol : variable PPQ
location: class MiniMiniMusicApp
Sequencer seq = new Sequencer(Sequencer,PPQ,4);
^
D:\JavaProg\head first\chap-11\MiniMiniMusicApp.java:18: javax.sound.midi.Sequencer is abstract; cannot be instantiated
Sequencer seq = new Sequencer(Sequencer,PPQ,4);
^
D:\JavaProg\head first\chap-11\MiniMiniMusicApp.java:19: cannot resolve symbol
symbol : method createTrack ()
location: interface javax.sound.midi.Sequencer
Track track = seq.createTrack();
^
D:\JavaProg\head first\chap-11\MiniMiniMusicApp.java:31: cannot resolve symbol
symbol : method setSequence (javax.sound.midi.Sequencer)
location: interface javax.sound.midi.Sequencer
player.setSequence(seq);
^
5 errors

Tool completed with exit code 1

Thanks
Divya
 
Campbell Ritchie
Sheriff
Pie
Posts: 49447
62
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You are using Sequencer which is the name of an interface as an argument to the Sequencer constructor.
You can't create an object of Sequencer because (as any interface does) it has only empty methods. I am not familiar with this example, though people do seem to ask questions about it her quite frequently. Go back to the Head First book and see what they say there. They might have another example on the next page where the Sequencer is changed to a class, and you might have to run the two together.
 
marc weber
Sheriff
Posts: 11343
Java Mac Safari
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
As Campbell pointed out, the problem is with this line...

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

I think you want a new Sequence here -- not a new Sequencer...

Sequence seq = new Sequence(Sequence.PPQ,4);
 
Campbell Ritchie
Sheriff
Pie
Posts: 49447
62
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sequence? Only one letter out
 
divya sharma
Ranch Hand
Posts: 87
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
oh!!! Thanks a lot for your help

Divya
 
marc weber
Sheriff
Posts: 11343
Java Mac Safari
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Campbell Ritchie:
Sequence? Only one letter out

That, and a period in place of a comma: Sequence.PPQ -- not Sequencer,PPQ.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic