简体   繁体   中英

Class is not Abstract?

private class HandlerClass implements ActionListener
    {
        public void actionPerfomed(ActionEvent event)
        {
            JOptionPane.showMessageDialog(null, String.format("%s", event.getActionCommand));
        }
    }

This is part of my code and when I compile, I get an error saying HandlerClass is not abstract and does not override abstract method actionPerformed(java.awt.event.ActionEvent) in java.awt.event.ActionListener . To my understanding, actionPerformed should override HandlerClass shouldn't it? I already tried adding " abstract " before the word class but then I get another error since I can't call an abstract class. I'm not sure if maybe there's an exception I can use to solve this?

Basically, you have a spelling mistake...

actionPerfomed

Should be

actionPerformed
           ^---- ;)

You may also want to use the @Override annotation which will tell you when you're attempting to override a method that doesn't exist in the parent classes...

@Override
public void actionPerformed(ActionEvent event)
{
    JOptionPane.showMessageDialog(null, String.format("%s", event.getActionCommand));
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM