5

Here is the java code

usageType = (String) c.getSrcValue("USAGETYPE");

c is a arraylist. I populate it with this field from DB. "USAGETYPE" NUMBER(*,0),

I get the following error

java.lang.ClassCastException: java.math.BigDecimal cannot be cast to String

Can you please help me out

2 Answers 2

10

Well, you cannot convert an object to a string by casting. Not in Java, in any case.

Try

usageType = c.getSrcValue("USAGETYPE").toString();

That is, if you actually need it as a string, which smells a little dubious in the first place. Usually the only place where numbers are needed as strings is the UI and you've got appropriate other places to do that conversion, normally (e.g. CellRenderers in Swing).

Sign up to request clarification or add additional context in comments.

Comments

6

Simply write

usageType = c.getSrcValue("USAGETYPE").toString();

or

usageType = ""+c.getSrcValue("USAGETYPE");

1 Comment

@trashgod : thanks for formatting. I will take care of putting in formatted code henceforth :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.