commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Emmanuel Bourg <sma...@lfjr.net>
Subject Re: Configuration: init problem
Date Wed, 10 Nov 2004 16:17:17 GMT
Hello, if the configuration file doesn't exist yet, use the empty 
constructor :

Configuration pc = new PropertiesConfiguration();

Emmanuel Bourg




Javier wrote:
> Hello
> 
> I´ve problems with my first configuration use.
> 
> I want to try to load a config file, if it fails,
> create a new one.
> 
> My code is:
> 
> +++++++++++++++++++++++++++++
> 
> try {
>             pc = new PropertiesConfiguration("a.ini");
> 
> 
>         } catch (ConfigurationException ce) {
>             try {
>                 pc = new PropertiesConfiguration();
>                 pc.addProperty("dbClassName",
> "SQLite.JDBCDriver");
>                 pc.addProperty("dbURL",
> "jdbc:sqlite://sogox.db");
>                 pc.addProperty("phonesFilePath",
> "c:\\\\");
>                 pc.save("a.ini");
>                 
>             } catch (ConfigurationException ce1) {
>                 System.err.println(ce.getMessage());
>             }
>         }
> 
> ++++++++++++++++++++++++++++++
> 
> but, I received a error message:
> 
> Exception in thread "main"
> java.lang.NullPointerException
>         at
> org.apache.commons.configuration.ConfigurationUtils.getBasePath(Confi
> gurationUtils.java:337)
> 
> 
> I guess it´s due to the fact that the file doesn´t
> exist and then new PropertiesConfiguration gives a
> null value.
> 
> Well, my doubt is how should I do this ? which is the
> "best practice" ? should I use xml instead of
> properties ?
> 
> 
> Thanks in advance
> 
> Javier
> 
> 
> 
> 
> 		
> __________________________________ 
> Do you Yahoo!? 
> Check out the new Yahoo! Front Page. 
> www.yahoo.com 
>  
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: commons-user-help@jakarta.apache.org
> 
> 
> 

---------------------------------------------------------------------
To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-user-help@jakarta.apache.org


Mime
View raw message