Forums Register Login

Head First : MiniMiniMusicApp

+Pie Number of slices to send: Send
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
1
+Pie Number of slices to send: Send
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.
+Pie Number of slices to send: Send
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);
+Pie Number of slices to send: Send
Sequence? Only one letter out
+Pie Number of slices to send: Send
oh!!! Thanks a lot for your help

Divya
+Pie Number of slices to send: Send
 

Originally posted by Campbell Ritchie:
Sequence? Only one letter out


That, and a period in place of a comma: Sequence.PPQ -- not Sequencer,PPQ.
All of the following truths are shameless lies. But what about this tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com


reply
reply
This thread has been viewed 1265 times.
Similar Threads
Head First Java Chapter 11 MiniMiniMusicApp
Application doesn't quit -- MiniMiniMusicApp sample from Head First Java
Head First Java chapter 11 MiniMiniMusicApp
Java sounds not working!
MiniMiniMusicApp? anyone else having issues with it?
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 28, 2024 07:51:27.