I am working on an application in which I wanted to replace a lot of static
variables by properties set in the System.props.
I made a Property class in which I store a number of properties. When I run
my application it first executes the following code:
ProgramProperties progProps = new ProgramProperties();
System.setProperties(progProps.getProperties());
But then when a JFrame is created after that I get the following exception:
java.lang.NullPointerException
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:140)
at
java.awt.GraphicsEnvironment.getLocalGraphicsEnvironment(GraphicsEnvironment
.java:62)
at java.awt.Window.init(Window.java:224)
at java.awt.Window.<init>(Window.java:268)
at java.awt.Frame.<init>(Frame.java:398)
at javax.swing.JFrame.<init>(JFrame.java:198)
at tohil.framework.TohilController.<init>(TohilController.java:36)
at tohil.framework.TohilRoot.<init>(TohilRoot.java:130)
at tohil.framework.TohilRoot.main(TohilRoot.java:118)
Exception in thread "main"
If I don't call the System.setProperties then the application works fine
(except for that I get some exceptions because some required properties are
not set ;)), but when I add those 2 lines of code the exception occurs.
Also, when I set the properties and then try to create a directory before I
create the JFrame I get the following exception:
java.lang.NullPointerException
at java.io.Win32FileSystem.normalize(Win32FileSystem.java:163)
at java.io.Win32FileSystem.getUserPath(Win32FileSystem.java:272)
at java.io.Win32FileSystem.resolve(Win32FileSystem.java:288)
at java.io.File.getCanonicalPath(File.java:513)
at java.io.FilePermission$1.run(FilePermission.java:209)
at java.security.AccessController.doPrivileged(Native Method)
at java.io.FilePermission.init(FilePermission.java:203)
at java.io.FilePermission.<init>(FilePermission.java:253)
at java.lang.SecurityManager.checkRead(SecurityManager.java:887)
at java.io.File.exists(File.java:677)
at java.io.File.mkdirs(File.java:1118)
at tohil.framework.LockFile.checkAndCreate(LockFile.java:29)
at tohil.framework.TohilRoot.<init>(TohilRoot.java:129)
at tohil.framework.TohilRoot.main(TohilRoot.java:117)
Exception in thread "main"
Does anyone have any idea what could be the problem here?
Thanks in advance,
Yereth
In article <3f9be6af$0$445$1b62...@news.wanadoo.nl>, on Sun, 26 Oct 2003
16:22:29 +0100, "Yereth Jansen"
<ma...@yereth.tk> wrote:
| Hello all,
|
| I am working on an application in which I wanted to replace a lot of static
| variables by properties set in the System.props.
| I made a Property class in which I store a number of properties. When I run
| my application it first executes the following code:
|
| ProgramProperties progProps = new ProgramProperties();
| System.setProperties(progProps.getProperties());
Yuck. You've just deleted the existing properties.
You need to do something like:
// Get existing properties...
Properties properties = System.getProperties();
// Add some new properties...
properties.put( "property1", "value1" );
...
properties.put( "propertyX", "valueX" );
<davidp />
- --
David Postill
-----BEGIN PGP SIGNATURE-----
Version: PGP 8.0.3 - not licensed for commercial use: www.pgp.com
Comment: Get key from pgpkeys.mit.edu:11370
iQA/AwUBP5vszXxp7q1nhFwUEQKYWwCg+wnma+TyIjzzYC7zzGNEE8j63YsAn0lU
Ud+N89xlC0e2EzXuCmw/cNkB
=VC4m
-----END PGP SIGNATURE-----
Oops! Why didn't I think of that... maybe I should read the javadoc better
next time... Thank you very much. :)
Yereth