Hi,
The code
int n = (int) java.lang.Math.round(Double.parseDouble((String)
args.get(0)));
r = (int) java.lang.MathException in thread "main"
resulted in the following ex:
java.lang.NumberFormatException: For input string: "5.0"
at
java.lang.NumberFormatException.forInputString(NumberFormatException.java:48)
at java.lang.Integer.parseInt(Integer.java:456)
at java.lang.Integer.parseInt(Integer.java:497)
The args.get(0) represents "5.0" as input. I have tried the most common
way
int n = Integer.parseInt((String) args.get(0));
but eventually failed and later evolved to the version as at the front
of this post. BTW, I use JAVA REFLECTION to do so. The code is inside a
class which is called by a reflection procedure.
What is it going wrong? Thx~!
Oliver Hirschi - 23 Jan 2006 07:05 GMT
moopT <samhng@gmail.com> wrote:
> Hi,
> The code
> int n = (int) java.lang.Math.round(Double.parseDouble((String)
> args.get(0)));
use "args[0]" instead of "args.get(0)"

Signature
Oliver Hirschi
http://www.FamilyHirschi.ch
Knute Johnson - 23 Jan 2006 07:13 GMT
moop™ wrote:
> Hi,
> The code
[quoted text clipped - 16 lines]
> class which is called by a reflection procedure.
> What is it going wrong? Thx~!
Well you can't Integer.parseInt() a string with a decimal point in it.
The Double.parseDouble() ought to work but are you sure that you don't
have any spaces in it? Are you sure that (String)args.get(0) is
returning a string?

Signature
Knute Johnson
email s/nospam/knute/
NullBock - 23 Jan 2006 08:05 GMT
It looks to me like you have a problem with your reflection:
> at java.lang.Integer.parseInt(Integer.java:456) !! The *Integer* class is parsing it!
Are you sure you're not dynamically loading/using a stale version of
the class file?
Walter Gildersleeve
Freiburg, Germany
______________________________________________________
http://linkfrog.net
URL Shortening
Free and easy, small and green.