2016-03-26 36 views
1

In meiner actionPerformed-Methode rufe ich "copy()" wer Klone Objekte, aber der Compiler gibt mir diesen Fehler: "java.awt.event.ActionListener; überschriebene Methode wirft nicht java.lang.CloneNotSupportedException ", Was kann ich tun?CloneNotSupportedException in actionPerformed

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

Danke

Antwort

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

Sie haben es zu handhaben.

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