Java 中的配置异常?

发布于 2024-08-24 18:32:39 字数 640 浏览 2 评论 0原文

决定使用 Apache 的通用配置包来解析 XML 文件。

我决定做一个:

XMLConfiguration xmlConfig = new XMLConfiguration(file);

Eclipse 抱怨我没有捕获异常(未处理的异常类型 ConfigurationException),所以我用 try/catch 命中了可靠的包围并且它添加了以下代码:

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 建议添加它时它给了我这个错误。

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

I decided to do a:

XMLConfiguration xmlConfig = new XMLConfiguration(file);

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

However now it's complaining:

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

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

昇り龍 2024-08-31 18:32:39

org.apache.commons.configuration.ConfigurationException 扩展了 org.apache.commons.lang.exception.NestableException。

您的道路上也有 Commons Lang 吗?如果不是,Eclipse 将无法解析 ConfigurationException 类,并且您将收到该错误。

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

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.

请帮我爱他 2024-08-31 18:32:39

您需要 Apache Commons Lang 2.6

(当前版本的 Apache Common Configuration (1.8) 不会适用于 Apache Common Lang 库的 3.1 版本,您可能需要在此处检查通用配置依赖项)

You need Apache Commons Lang 2.6

(Current release of Apache Common Configuration (1.8) wont works with version 3.1 of Apache Common Lang library, you might need to check Common configuration dependencies here )

一抹淡然 2024-08-31 18:32:39

我也面临这个问题。
要解决此问题 - 请从 http://commons.apache.org/ 下载 commons-lang-2.6.jar正确/commons-lang/download_lang.cgi
并将此 commons-lang-2.6.jar 添加到项目的构建路径中。这应该可以解决你的问题。

I also faced this problem.
To fix this - Please download commons-lang-2.6.jar from http://commons.apache.org/proper/commons-lang/download_lang.cgi
and add this commons-lang-2.6.jar to your project's build path. this should solve your problem.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文