getInteger

G

Gordon Beaton

Why baudRate = null

If you have a *System* property (e.g. java -Dbaudrate=19200) you can
use:

baudRate = Integer.getInteger("baudrate");

With your property file, you can use:

baudRate = Integer.parseInt(props.getProperty("baudrate"));

You don't need to specify "java.lang"

/gordon
 
H

Harald Hein

pierre said:
baudRate =
java.lang.Integer.getInteger(props.getProperty("baudrate"));
return null

Why baudRate = null

Read the API documentation again. getInteger uses System.getProperty().
So what you have coded is the equivalent of

baudRate = System.getProperty("19200");

And (a) there is usually no property called "19200" in the system
properties, (b) you don't want a property called "19200", and (c) you
anyhow don't want the system properties, but your own. Use parseInt()
instead.

BTW: This is a case where a debugger is of much help. It pays to learn
using one.
 
L

Lothar Kimmeringer

On Thu, 18 Sep 2003 18:04:32 +0000, pierre wrote:

[...]

see answer to your multipost in comp.lang.java.help


Regards, Lothar
BTW: Fix the date on your computer. You're in CEST not GMT
--
Lothar Kimmeringer E-Mail: (e-mail address removed)
PGP-encrypted mails preferred (Key-ID: 0x8BC3CD81)

Always remember: The answer is forty-two, there can only be wrong
questions!
 
J

Jos A. Horsmeier

pierre said:
Hi,


I have a properties file:
baudrate = 19200

my program:
Integer BaudRate;
String srtbaudRate;

srtbaudRate = props.getProperty("baudrate"); // donne bien 19200
baudRate = java.lang.Integer.getInteger(props.getProperty("baudrate")); return null

Why baudRate = null

You've taken one step too many (read the API docs). Change that last line to --

baudRate = java.lang.Integer.getInteger("baudrate");

i.e. the getInteger( ... ) method does a System.properties lookup itself.

kind regards,

Jos
 
P

pierre

Hi,


I have a properties file:
baudrate = 19200

my program:
Integer BaudRate;
String srtbaudRate;

srtbaudRate = props.getProperty("baudrate"); // donne bien 19200
baudRate = java.lang.Integer.getInteger(props.getProperty("baudrate")); return null

Why baudRate = null

Thanks
 
P

pierre

pierre said:
Hi,


I have a properties file:
baudrate = 19200

my program:
Integer BaudRate;
String srtbaudRate;

srtbaudRate = props.getProperty("baudrate"); // donne bien 19200
baudRate = java.lang.Integer.getInteger(props.getProperty("baudrate"));
return null

Why baudRate = null

Thanks
Thank you for answers

Pierre
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,431
Messages
2,571,679
Members
48,796
Latest member
Greg L.

Latest Threads

Top