In actionPerformed(ActionEvent e)
you call encrypt()
, which is declared to throw Exception
. However, actionPerformed
neither catches this Exception (with try/catch around the call to encrypt()
) nor declares that it throws Exception
itself.
Your encrypt
method, however, does not truly throw Exception
. It swallows all Exceptions without even as much as logging a complaint. (Bad practice and bad style!)
Also, your encrypt
method does the following:
public static byte[] encrypt(String toEncrypt) throws Exception {
try{
....
return encrypted; // HERE YOU CORRECTLY RETURN A VALUE
} catch(Exception e) {
}
// YOU DO NOT RETURN ANYTHING HERE
}
That is, if you do catch any Exception, you discard it silently and then fall off the bottom of your encrypt
method without actually returning anything. This won't compile (as you see), because a method that is declared to return a value must either return a value or throw an Exception for every single possible code path.