This week's book giveaway is in the Java 8 forum.
We're giving away four copies of Java 8 in Action and have Raoul-Gabriel Urma, Mario Fusco, and Alan Mycroft on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes What kind of error is this? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "What kind of error is this?" Watch "What kind of error is this?" New topic
Author

What kind of error is this?

nani aman
Ranch Hand

Joined: Sep 22, 2004
Posts: 33
hi, its me again with a lot of blurr..
i had this error in my second class. It seem like lack of something but i couldn't figure it out. What actually i need to do?\

error :
addItemListener(java.awt.event.ItemListener) in javax.swing.AbstractButton cannot be applied to Class2.java

i hope someone can show me the way..
Thank you.
Ben Wood
Ranch Hand

Joined: Aug 14, 2001
Posts: 342
Maybe some code would help, but my guess is that you have not called the add method on an actual component (button?)

e.g.



SCJP 1.4, www.gsi3d.org.uk
nani aman
Ranch Hand

Joined: Sep 22, 2004
Posts: 33
This is some codes that used addItemListener, this is not button but a check box. bFinish is the only button i use in here.

qchk1Yes.addItemListener(this);
qchk1No.addItemListener(this);
qchk2Yes.addItemListener(this);
bFinish.addItemListener(this);

addWindowListener(new WindowAdapter(){
public void windowClosing(WindowEvent e){
System.exit(0);
}
});

thanks..
Ilja Preuss
author
Sheriff

Joined: Jul 11, 2001
Posts: 14112
Are you sure your class is implementing the ItemListener interface?


The soul is dyed the color of its thoughts. Think only on those things that are in line with your principles and can bear the light of day. The content of your character is your choice. Day by day, what you do is who you become. Your integrity is your destiny - it is the light that guides your way. - Heraclitus
nani aman
Ranch Hand

Joined: Sep 22, 2004
Posts: 33
i implemented the action listener in the class. I change qchk1Yes.addItemListener(this) to qchk1Yes.addActionListener but i still could get why they is error.
J Chandler
Ranch Hand

Joined: May 17, 2003
Posts: 32
Hi nani,

when we want to implement a Listener interface, we need to declare it
somewhere so the compiler knows.
That means either making our own listener class to handle all the methods
in the listener interface ...
OR, what would be best in this case, because ItemListener has only 1 method - itemStateChanged - we could simply state that we are implementing the ItemListener interface when declaring the class.

Example:-


and don't forget to code your own itemStateChanged method in Class2 - if the compiler knows you want to use ItemListener, it will be looking for your implementation of this method.

Example:-

hope that helps

[ October 19, 2004: Message edited by: J Chandler ]

[ October 19, 2004: Message edited by: J Chandler ]
[ October 19, 2004: Message edited by: J Chandler ]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: What kind of error is this?
 
Similar Threads
jsp error
simple question
help, my jsp can not display outside Root
how to access inner frame elements from parent document
Menu problem