Melvin Lai
Melvin Lai

Reputation: 911

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.

Upvotes: 1

Views: 27795

Answers (5)

Raj kiran M
Raj kiran M

Reputation: 11

You might also see some spaces in your string which can cause NumberFormatException . Trim the string .

Upvotes: 0

Peter Lawrey
Peter Lawrey

Reputation: 533870

The error message is telling you that the contents of the byte[] is not a number as text that it can decode.

There is nothing wrong with the code as you say, and no reason to suspect there is as the compiler is not giving you an error.

You have a runtime error based on the input you give it, so there is a problem with the input.

Upvotes: 0

user7016813
user7016813

Reputation: 31

If you receive a value that use it convert to BigDecimal. for example: String receiveValue = request.getParameter("xxx"); BigDecimal bigDecimal = new BigDecimal(receiveValue);

But problem is receiveValue is null or blank value, so that it post this problem.

Upvotes: 0

Alex Lockwood
Alex Lockwood

Reputation: 83311

The docs state that a NumberFormatException will be thrown if the input String is not a valid representation of a BigDecimal... so checking the code that creates the BigDecimal is a good place to start.

Upvotes: 0

Benjamin Gruenbaum
Benjamin Gruenbaum

Reputation: 276596

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.

Upvotes: 3

Related Questions