Java中的配置异常?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/2416980/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
ConfigurationException in Java?
提问by Federer
Decided to use Apache's Common Configuration package to parse an XML File.
决定使用 Apache 的 Common Configuration 包来解析 XML 文件。
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:
Eclipse 抱怨我没有捕获异常(Unhandled exception type ConfigurationException
),所以我点击了可信赖的surround with try/catch
,它添加了以下代码:
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.
我不明白为什么当 Eclipse 是建议添加它的时候它给了我那个错误。
采纳答案by skaffman
org.apache.commons.configuration.ConfigurationException
extends org.apache.commons.lang.exception.NestableException
.
org.apache.commons.configuration.ConfigurationException
延伸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.
你的道路上也有Commons Lang吗?否则,Eclipse 将无法解析ConfigurationException
该类,并且您将收到该错误。
回答by Massimo Fazzolari
You need Apache Commons Lang2.6
你需要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)
(Apache Common Configuration (1.8) 的当前版本不适用于 Apache Common Lang 库的 3.1 版,您可能需要在此处检查 Common configuration dependencies )
回答by Pankaj Kumar Katiyar
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.cgiand add this commons-lang-2.6.jar to your project's build path. this should solve your problem.
我也遇到了这个问题。要解决此问题 - 请从http://commons.apache.org/proper/commons-lang/download_lang.cgi下载 commons-lang-2.6.jar 并将此 commons-lang-2.6.jar 添加到您项目的构建路径中。这应该可以解决您的问题。