This week's book giveaway is in the Design forum.
We're giving away four copies of Design for the Mind and have Victor S. Yocco on-line!
See this thread for details.
Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Error in using Inner classes

 
Vinayak patil
Ranch Hand
Posts: 67
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I am having problems using inner classes in Java.

I was trying out a code given in "Head First Java" 2nd Ed. Page392.


I have an inner class that implements ControllerEventListener interface.

<Code> :

class MydrawPanel extends JPanel implements ControllerEventListener

{

//Code for the inner class

}


In the outer class I have instances of MyDrawPanel and Sequence.

<Code>

static MyDrawPanel m1 = new MyDrawPanel();
Sequencer sequencer = MidiSystem.getSequencer();

I get an error when I use this line:

sequencer.addControllerEventListener(m1,new int[] {127});

The Compilation error I get is
<error>
addControllerEventListener(javax.sound.midi.ControllerEventListener, int[]) in javax.sound.midi.Sequencer cannot be applied to (MyDrawPanel,int[]) .

I cannot understand why I am getting this error though MyDrawPanel implements ControllerEventListener.

Please let me know.

Thanks in advance

-Vinayak
 
Jesper de Jong
Java Cowboy
Saloon Keeper
Posts: 15214
36
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Look closely at your code again, you're probably making a mistake somewhere, maybe just a typing error.

In your code above, you first call your inner class MydrawPanel with a lower case d, but you call it MyDrawPanel with an upper case D later on.
 
Vinayak patil
Ranch Hand
Posts: 67
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes,the error was in the typing as you pointed out.

I did not get a class not found error as there was another class MyDrawPanel in the same folder as this file.

Thanks a lot


-Vinayak
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic