File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Beginning Java and the fly likes Error in using Inner classes Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of REST with Spring (video course) this week in the Spring forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Error in using Inner classes" Watch "Error in using Inner classes" New topic

Error in using Inner classes

Vinayak patil
Ranch Hand

Joined: Aug 30, 2005
Posts: 67
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.


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


"I can resist everything except temptation"
Jesper de Jong
Java Cowboy
Saloon Keeper

Joined: Aug 16, 2005
Posts: 15042

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.

Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 8 API documentation
Vinayak patil
Ranch Hand

Joined: Aug 30, 2005
Posts: 67
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

It is sorta covered in the JavaRanch Style Guide.
subject: Error in using Inner classes
It's not a secret anymore!