Java中的ConfigurationException?

Fed*_*rer 23 java apache-commons

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

我决定做一个:

XMLConfiguration xmlConfig = new XMLConfiguration(file);
Run Code Online (Sandbox Code Playgroud)

Eclipse抱怨我没有捕获异常(Unhandled exception type ConfigurationException),所以我点击了可靠性surround with try/catch并添加了以下代码:

try 
    {
        XMLConfiguration xmlConfig = new XMLConfiguration(file);
    } 
    catch (ConfigurationException ex) 
    {
        ex.printStackTrace();
    }
Run Code Online (Sandbox Code Playgroud)

然而现在它抱怨:

No exception of type ConfigurationException can be thrown; an exception type 
must be a subclass of Throwable
Run Code Online (Sandbox Code Playgroud)

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

ska*_*man 29

org.apache.commons.configuration.ConfigurationException延伸org.apache.commons.lang.exception.NestableException.

你的道路上还有Commons Lang吗?如果没有,Eclipse将无法解析ConfigurationException该类,您将收到该错误.

  • @ 8EM:看起来你也需要Commons Collections. (4认同)

Mas*_*ari 20

你需要Apache Commons Lang 2.6

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


Pan*_*yar 7

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