2016-03-26 5 views
1

В моем методе actionPerformed я вызываю «copy()», который клонирует объекты, но компилятор дает мне эту ошибку: «java.awt.event.ActionListener; переопределенный метод не бросает java.lang.CloneNotSupportedException ", что я могу сделать?CloneNotSupportedException в actionPerformed

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

Спасибо

ответ

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. [...]

Вы должны справиться с этим.

@Override 
public void actionPerformed(ActionEvent e) { 
    //code 
    try { 
     copy(); 
    } catch (CloneNotSupportedException cnse) { 
     cnse.printStackTrace(); 
    } 
}