我需要将BigDecimal值转换为字符串。我做了如下:
@Column(name="CASE_ID", precision=22, scale=0)
public BigDecimal getCaseId() {
return this.caseId;
}
public void setCaseId(BigDecimal caseId) {
this.caseId = caseId;
} String caseId = "";
caseId = vList.get(i).getCaseId().toString();
dataCell.setCellValue(caseId);
我得到一个运行时异常,如下所示:
2013-03-11 14:49:11,046 WARN [HTTPThreadGroup-4] org.apache.struts.action.RequestProcessor:抛出未处理的异常: class java.lang.ClassCastException
包装异常:
java.lang.ClassCastException: [Ljava.lang.Object;
at com.report.getExport(ExportToExcelAction.java:468)
at com.report.getExport.view(ExportToExcelAction.java:134)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:585)
at org.apache.struts.actions.DispatchAction.dispatchMethod(DispatchAction.java:280)
at gov.pbgc.spectrum.util.SpectrumLookupDispatchAction.execute(SpectrumLookupDispatchAction.java:119)
at org.apache.struts.action.RequestProcessor.processActionPerform(RequestProcessor.java:484)
at org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:274)
at org.apache.struts.action.ActionServlet.process(ActionServlet.java:1482)
at org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:525)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:763)
我知道toString()
会将BigDecimal
转换为String
。我没有得到编译时异常,但我确实得到了运行时异常。任何见解?
答案 0 :(得分:0)
好的..然后按以下方式更改您的代码:
caseId = ((CsValidateReport)vList.get(i)).getCaseId();
而不是这一行:
String caseId = "";
使用String sCaseId = "";
然后您可以按以下步骤操作:
caseId = ((CsValidateReport)vList.get(i)).getCaseId();
sCaseId = caseId.toPlainString() ;
dataCell.setCellValue(sCaseId );