File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Beginning Java and the fly likes Head First : MiniMiniMusicApp Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Head First : MiniMiniMusicApp" Watch "Head First : MiniMiniMusicApp" New topic
Author

Head First : MiniMiniMusicApp

divya sharma
Ranch Hand

Joined: Jan 25, 2007
Posts: 87
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


Divya
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38851
    
  23
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

Joined: Aug 31, 2004
Posts: 11343

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);


"We're kind of on the level of crossword puzzle writers... And no one ever goes to them and gives them an award." ~Joe Strummer
sscce.org
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38851
    
  23
Sequence? Only one letter out
divya sharma
Ranch Hand

Joined: Jan 25, 2007
Posts: 87
oh!!! Thanks a lot for your help

Divya
marc weber
Sheriff

Joined: Aug 31, 2004
Posts: 11343

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

That, and a period in place of a comma: Sequence.PPQ -- not Sequencer,PPQ.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Head First : MiniMiniMusicApp