G'day..

Am new to this whole object oriented stuff. But keen to learn. Am trying to compile this class but keep getting the following error when i declare anything that 'implements'. i remove the declarations and all subsequent code references and she compiles.. any ideas??

*********************START_OF_ERROR**********************
ChatClientApplication.java:6: ChatClientApplication is not abstract and does not override abstract method actionPerformed(java.awt.event.ActionEvent) in java.awt.event.ActionListener public class ChatClientApplication extends Frame implements ActionListener, Item
Listener, WindowListener
^
1 error
***********************END_OF_ERROR**********************
Cheers..
:eek:

Dani AI

Generated

Two separate lessons are hiding in this thread: one compile-time (missing listener methods) and one runtime (class not found). correctly pointed out the compile error — when a class declares implements SomeListener the compiler expects every method the interface declares. Small mismatches (wrong parameter type, wrong visibility, or a typo in the method name) make the method effectively “missing,” so the class must either implement them all or be declared abstract.

A short checklist for listener-related compile errors:

  • Method signatures must match exactly and be public (interface methods are public).
  • For multi-method interfaces (for example the window listener family) you either implement every method or use an adapter class to override only what you need.
  • Use @Override when your compiler supports it — it catches signature mistakes early.
  • Keep imports consistent or use fully-qualified names to avoid accidentally implementing a different method signature.

The NoClassDefFoundError you saw at runtime means the JVM couldn’t load the class file. Typical causes: running the JVM with the .class suffix, the class file isn’t on the runtime classpath, or package/directory layout doesn’t match the declared package. Best practices: run the JVM with the class’s binary name (no .class), ensure the current directory is on the classpath (or use an explicit classpath flag), and if the class declares a package run it by its fully-qualified name from the directory above the package root.

If only one or two window events are needed, prefer an adapter to avoid empty stubs; for example:

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

These checks (signatures, visibility, classpath, package layout) cover the common mistakes that produced the errors discussed by and .

Recommended Answers

All 4 Replies

To implement an interface (in this case ActionListener or ItemListener), you must write all the functions that the interface provides. One such function you're missing is actionPerformed(ActionEvent). If you put this function into your ChatClientApplication class, it will stop complaining.

Put this in your class:

public void actionPerformed(java.awt.event.ActionEvent e)
 {
 }

Hope this helps!


Ed


*********************START_OF_ERROR**********************
ChatClientApplication.java:6: ChatClientApplication is not abstract and does not override abstract method actionPerformed(java.awt.event.ActionEvent) in java.awt.event.ActionListener public class ChatClientApplication extends Frame implements ActionListener, Item
Listener, WindowListener
^
1 error
***********************END_OF_ERROR**********************
Cheers..
:eek:

Hi Ed,

that's brilliant! Thankyou, code compiles now..

-> ha! So now of course I attempt to run it and get:

C:\Java Chat Application WIP\My Source>java ChatClientApplication.class
Exception in thread "main" java.lang.NoClassDefFoundError: ChatClientApplication
/class

I am not 'constructing' correctly??, i.e.

public class ChatClientApplication extends Frame implements ActionListener, ItemListener, WindowListener

and then:

//Class constructor method..
public ChatClientApplication()
{
// initialise the user interface
init();
}

and then:

//Main method to bring everything together..
public static void main(String args[])
{
new ChatClientApplication();
}

...if anyone is bored and wants to help! eek:

Don't have the .class at the end.

Just run the line
java ChatClientApplication

Hope this helps. ;-)


Ed

Hi Ed,

that's brilliant! Thankyou, code compiles now..

-> ha! So now of course I attempt to run it and get:
----------------------------------------------------------------------
C:\Java Chat Application WIP\My Source>java ChatClientApplication.class
Exception in thread "main" java.lang.NoClassDefFoundError: ChatClientApplication
/class

----------------------------------------------------------------------

Good point, thankyou Ed.

Turns out I did not have my CLASSPATH environment variable set correctly (set CLASSPATH=), so class files could not be found and nothing was able to run..

Thanks for help anyway..

:-|

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.