开发者

not able to convert bigdecimal to string in java

开发者 https://www.devze.com 2023-01-11 21:16 出处:网络
Here is the java code u开发者_运维百科sageType = (String) c.getSrcValue(\"USAGETYPE\"); c is a arraylist.

Here is the java code

u开发者_运维百科sageType = (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


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).


Simply write

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

or

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

精彩评论

暂无评论...
验证码 换一张
取 消