1

In my actionPerformed method i'm calling "copy()" who clones objects, but the compiler gives me this error: "java.awt.event.ActionListener; overridden method does not throw java.lang.CloneNotSupportedException", what can i do?

        public void actionPerformed(ActionEvent e){
    if (e.getSource() instanceof JButton) {
      copy(); ...

Thank You

Trevor
  • 11
  • 1

1 Answers1

0

You can not add throwed checked exception to a method while overriding it.

[...] the overriding method should not throw checked exceptions that are new or broader than the ones declared by the overridden method. [...]

You have to handle it.

@Override
public void actionPerformed(ActionEvent e) {
    //code
    try {
        copy();
    } catch (CloneNotSupportedException cnse) {
        cnse.printStackTrace();
    }
}
Yassin Hajaj
  • 21,337
  • 9
  • 51
  • 89