Java获取错误'未处理的异常类型XYZ'

时间:2012-06-08 14:37:27

标签: java macos jce

我有这段代码:

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();

当编译时出现此错误:

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

在研究错误时,我发现this。但在下载,安装和verifying无限强度管辖政策文件是最新的后,我仍然收到错误。

2 个答案:

答案 0 :(得分:2)

您的错误非常明确,与无限制的管辖区加密文件无关。它告诉你有未处理的检查异常。

throws Exception添加到构造函数中,使其如下所示:

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

答案 1 :(得分:1)

您是否也将它们安装到/System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Home/lib/security?

相关问题