You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@commons.apache.org by Javier <xl...@yahoo.com> on 2004/11/10 16:56:39 UTC
Configuration: init problem
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
Re: Configuration: init problem
Posted by Oliver Heger <Ol...@t-online.de>.
Javier,
I think you have spotted a bug in [configuration]. Your code should work. If the file name you provide is invalid, a ConfigurationException rather than a NullPointerException should be thrown.
I opened a bugzilla ticket for this bug (no 32236) and will now work on a fix.
Oliver
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
Re: Configuration: init problem
Posted by Emmanuel Bourg <sm...@lfjr.net>.
Javier wrote:
>
> Thanks for your reply but..How sould my application
> know the file doesn´t exist ? Should check using
> File.exists or should use a Properties method that I
> unknow ?
We do not support optional files yet, you can use the following workaround:
File file = new File("a.ini");
file.createNewFile();
Configuration conf = new PropertiesConfiguration(file);
Emmanuel Bourg
---------------------------------------------------------------------
To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-user-help@jakarta.apache.org
Re: Configuration: init problem
Posted by Javier <xl...@yahoo.com>.
--- Emmanuel Bourg <sm...@lfjr.net> wrote:
> Hello, if the configuration file doesn't exist yet,
> use the empty
> constructor :
>
> Configuration pc = new PropertiesConfiguration();
>
Thanks for your reply but..How sould my application
know the file doesn�t exist ? Should check using
File.exists or should use a Properties method that I
unknow ?
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
Re: Configuration: init problem
Posted by Emmanuel Bourg <sm...@lfjr.net>.
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