Re: Java compilation error message.
- From: Jeffrey Spoon <JeffreySpoon@xxxxxxxxxxx>
- Date: Mon, 28 Nov 2005 22:02:20 +0000
In message <1133213031.701119.288850@xxxxxxxxxxxxxxxxxxxxxxxxxxxx>, ri.johnson@xxxxxxxx writes
Attempting to write my first java program that accepts user input. When I add the listner events to the code it will not compile. Below is the code along with the error message:
Code:
import javax.swing.*; import java.awt.event.*;
public class LottoEvent implements ItemListener, ActionListener, Runnable {
}
Compilation Error message:
javac LottoEvent.Java: LottoEvent is not abstract and does not override abstract method itemStateChanged(java.awt.event.ItemEvent) in java.awt.event.ItemListener public class LottoEvent implements ItemListener, ActionListener, Runnable
^
1 error Any ideas on how to fix it would be appreciated.
Try
import javax.swing.*; import java.awt.event.*;
public class LottoEvent implements ItemListener, ActionListener, Runnable {
public void run() {}public void actionPerformed (ActionEvent evt) {}public void itemStateChanged(ItemEvent item) {}}
That error is telling you that you are implementing an interface (or in this case interfaces). Interfaces enforce certain methods, so when you implement the interface you have to implement the methods of the interface. That is why you're getting the errors.
See:
http://java.sun.com/j2se/1.5.0/docs/api/java/awt/event/ItemListener.html
http://java.sun.com/j2se/1.5.0/docs/api/java/awt/event/ActionListener.htm l
http://java.sun.com/j2se/1.5.0/docs/api/java/lang/Runnable.html
BTW the code you posted does not give the error you claimed, it says this:
C:\JAVA\LottoEvent.java:4: LottoEvent should be declared abstract; it does not define run() in LottoEvent
public class LottoEvent implements ItemListener, ActionListener, Runnable {
I take it that was a typo or mistake ;)
-- Jeffrey Spoon
.
- References:
- Java compilation error message.
- From: ri . johnson
- Java compilation error message.
- Prev by Date: Re: (help plz) help me in downloading weblogic latest version
- Next by Date: Tomcat permission to write to Apache
- Previous by thread: Java compilation error message.
- Next by thread: Re: Java compilation error message.
- Index(es):
Relevant Pages
|