Java中的配置异常? [英] ConfigurationException in Java?

查看:31
本文介绍了Java中的配置异常?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

决定使用 Apache 的 Common Configuration 包来解析 XML 文件.

Decided to use Apache's Common Configuration package to parse an XML File.

我决定做一个:

XMLConfiguration xmlConfig = new XMLConfiguration(file);

Eclipse 抱怨我没有捕获到异常(未处理的异常类型 ConfigurationException),所以我用 try/catch 击中了可信赖的 surround 并添加了以下代码:

To which Eclipse complained that I haven't caught an exception(Unhandled exception type ConfigurationException), so I hit the trusty surround with try/catch and it added the following code:

try 
    {
        XMLConfiguration xmlConfig = new XMLConfiguration(file);
    } 
    catch (ConfigurationException ex) 
    {
        ex.printStackTrace();
    }

但是现在它在抱怨:

No exception of type ConfigurationException can be thrown; an exception type 
must be a subclass of Throwable

当 Eclipse 是建议添加它的那个时,我不明白为什么它给了我那个错误.

I don't understand why it's gave me that error when Eclipse is the one that suggested to add it.

推荐答案

org.apache.commons.configuration.ConfigurationException extends org.apache.commons.lang.exception.NestableException.

你的道路上也有 Commons Lang 吗?否则,Eclipse 将无法解析 ConfigurationException 类,您将收到该错误.

Do you have Commons Lang on your path also? If not, Eclipse will fail to resolve the ConfigurationException class, and you'll get that error.

这篇关于Java中的配置异常?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆