• Post Reply Bookmark Topic Watch Topic
  • New Topic

BigDecimal Problem  RSS feed

 
J D Kiran
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
My code
<<private BigDecimal addPercentageClosing = new BigDecimal(0);>>
works fine in jdk 1.4.2_03 on windows machine and 1.5.0_06 on solaris but it fails in jdk 1.5.0_07 on solaris.
<<Error Msg>>
Caused by: java.lang.NoSuchMethodError: java.math.BigDecimal.<init>(I)V

It may work if it change it to
[private BigDecimal addPercentageClosing =new BigDecimal((Double)0);]

But I simply want to know is it because of Version? is this not addressed in 1.5.0_07
 
Anubhav Anand
Ranch Hand
Posts: 341
Firefox Browser Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
monkWhoSoldHisJDK,
Welcome to JavaRanch!

We're pleased to have you here with, but there are a few rules that need to be followed, and one is that proper names arerequired. Please take a look at the JavaRanch Naming Policyand adjust your display name to match it.

In particular, your display name must be a first and a last name separated by a space character, and must not be obviously fictitious.
 
Anubhav Anand
Ranch Hand
Posts: 341
Firefox Browser Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please use appropraite tags to make your message more readable.


Works, well with JDK5.0 also on windows machine.

But,


would definitely give error as it won't cast from an integer to Double.
 
J D Kiran
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks 4 your guidelines on code of conduct.

would definitely give error as it won't cast from an integer to Double.
if so, what is the type of
0
in my code

if it is already
int
it should work in 1.5
else it should cast to
Double
when compiled in 1.4
 
J D Kiran
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Reformatted.

Thanks 4 your guidelines on code of conduct.

would definitely give error as it won't cast from an integer to Double.
if so, what is the type of 0 in my code new BigDecimal(0);

if it is already int it should work in 1.5
else it should cast to Double when compiled in 1.4
 
Anubhav Anand
Ranch Hand
Posts: 341
Firefox Browser Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Your name still doesn't comply with the standards.
Please take a look at the JavaRanch Naming Policyand adjust your display name to match it.

In particular, your display name must be a first and a last name separated by a space character, and must not be obviously fictitious.
 
Anubhav Anand
Ranch Hand
Posts: 341
Firefox Browser Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by JDKiran:
Reformatted.

Thanks 4 your guidelines on code of conduct.

would definitely give error as it won't cast from an integer to Double.
if so, what is the type of 0 in my code new BigDecimal(0);

if it is already int it should work in 1.5
else it should cast to Double when compiled in 1.4



Yes, it is int and it will work in 1.5. But, I doubt about 1.4 as implicit casting is absent in it.
 
J D Kiran
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
By "real name", we mean either your own actual, personal name, or a name that at least looks like it could belong to a real person.

You can even use an initial or initials for the first name if you like (but not the last).

.
.
.

It is not working in 1.5 and giving error at runtime saying no such method
Hence this topic is posted.
 
Jesper de Jong
Java Cowboy
Sheriff
Posts: 16060
88
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello J D Kiran, I'm a moderator here on JavaRanch. Your name "J D Kiran" is fine - initials for the first name are allowed. Thank you.

BigDecimal indeed has a constructor that takes an int since Java 5. If it doesn't work, then check if you are accidentally using an older version of Java. What does java -version print? Do you have multiple JDKs or JREs installed on the machine on which it doesn't work? Do those interfere with each other (for example, Java 5 picking up the libraries of Java 1.4 for some reason)? What does your classpath look like? Did you include Java system libraries in the classpath (you shouldn't do that)?
[ March 11, 2008: Message edited by: Jesper Young ]
 
J D Kiran
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
since it wanted to retain my source as 1.5 and target as 1.4
i have simply did this
JAVA_HOME=/usr/jdk/j2sdk1.4.2_12
export JAVA_HOME

My problem is solved.

Thanks for overwhelming response
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!