Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / First Aid / November 2005

Tip: Looking for answers? Try searching our database.

Java compilation error message.

Thread view: 
ri.johnson@juno.com - 28 Nov 2005 21:23 GMT
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.
Jeffrey Spoon - 28 Nov 2005 22:02 GMT
>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
[quoted text clipped - 21 lines]
>                                     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 ;)

Signature

Jeffrey Spoon

Roedy Green - 28 Nov 2005 22:35 GMT
>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

This message sounds misleading. I think what it means is you failed to
provide a suitable itemStateChanged method to implement ItemListener.
Signature

Canadian Mind Products, Roedy Green.
http://mindprod.com Java custom programming, consulting and coaching.

tip - 29 Nov 2005 05:08 GMT
If you have a class which is implemented from an Interface. You have to
add all the implemented methods.

> 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
[quoted text clipped - 21 lines]
>                                      1 error
> Any ideas on how to fix it would be appreciated.


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.