Search code examples
javabigdecimal

BigDecimal Exception message


What does this means?

Exception in thread "main" java.lang.NumberFormatException
java.math.BigDecimal.<init>(Unknown Source)

But when I click on the line that would be causing the problem, there was no warning nor error. So, how do I resolve this issue? My code still runs fine, but I am clueless why my console displayed that.

EDIT 2

I am allowed to show this much of the codes, I hope you can understand.

byte[] c = new byte[13];
System.arraycopy(buf, pos, c, 0, 10);
System.arraycopy(buf, pos + 10, c, 11, 2);
c[10] = '.';
return new IsoValue(type, new BigDecimal(new String(c)), null);

Base on the link given by @Benjamin, there shouldn't be a problem with it.


Solution

  • Let's see.

    The easiest way to know what an exception is is to check the API,

    First, let's open the BigDecimal API

    Exception in thread "main" java.lang.NumberFormatException
    java.math.BigDecimal.<init>(Unknown Source)
    

    Means your code threw an exception, on its main execution thread. The exception was of type NumberFormatException, and it was thrown in BigDecimal

    Let's see what the API has to say about this:

    Throws: NumberFormatException - if in is not a valid representation of a BigDecimal.

    (in is the input char array).

    So, this exception means you're creating a BigDecimal with an invalid value. Check the code that constructs the BigDecimal. There are also a bunch of other constructors on BigDecimal, you'll find the reason depending on the overload you're using there.