owen gerig
owen gerig

Reputation: 6172

Java getting error 'Unhandled exception type XYZ'

I have this code:

class Crypt
{
    Key KEY;
    String TD;
    Cipher aes = Cipher.getInstance("AES/CBC/PKCS5Padding");

    KeyGenerator keyGen = KeyGenerator.getInstance("AES");

public Crypt()
{
    int keyLength = 192;
    keyGen.init(keyLength);
    KEY = keyGen.generateKey();

Which when compiles gives this error:

Exception in thread "main" java.lang.Error: Unresolved compilation problems: 
    Unhandled exception type NoSuchAlgorithmException
    Unhandled exception type NoSuchPaddingException
    Unhandled exception type NoSuchAlgorithmException

When researching the error I found this. But after downloading, installing and verifying that Unlimited Strength Jurisdiction Policy Files are up to date I am still getting the error.

Upvotes: 0

Views: 1165

Answers (2)

Edvin Syse
Edvin Syse

Reputation: 7297

Did you also install them into /System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Home/lib/security?

Upvotes: 1

Sarel Botha
Sarel Botha

Reputation: 12710

Your error is very clear and doesn't have anything to do with the unlimited jurisdiction encryption files. It's telling you there are unhandled checked exceptions.

Add throws Exception to your constructor so it looks like this:

public Crypt() throws Exception
{
    int keyLength = 192;
    keyGen.init(keyLength);
    KEY = keyGen.generateKey();

Upvotes: 2

Related Questions