Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ConfigurationException in Java?

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.

like image 793
Federer Avatar asked Mar 10 '10 12:03

Federer


3 Answers

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.

like image 172
skaffman Avatar answered Nov 14 '22 03:11

skaffman


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 )

like image 41
Massimo Fazzolari Avatar answered Nov 14 '22 03:11

Massimo Fazzolari


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.

like image 8
Pankaj Kumar Katiyar Avatar answered Nov 14 '22 01:11

Pankaj Kumar Katiyar