0
传递小数时,我收到“不是有效的char构造函数输入”。我的代码如下。我研究并发现,通过从BigDecimal更改为Formatdeciaml解决了这个问题,但我无法做到这一点,因为我的映射器也需要更改。任何帮助,将不胜感激!!传递小数时接收“无效的char构造函数输入”错误
控制器
String postagePaid = (String) request.getParameter("tPostagePaid");
String insuranceFees = (String) request.getParameter("tInsuranceFees");
String registeredFees = (String) request.getParameter("tRegisteredFees");
String codFees = (String) request.getParameter("tCODFees");
String insRegisteredCODFees = (String) request.getParameter("tInsuranceFees");
System.out.println("insurance Fee: " + insuranceFees);
if (postagePaid != null && !insuranceFees.isEmpty()) { // postage paid amount
claim.setClPostagePaidAmt(new BigDecimal(postagePaid));
}
if (insuranceFees != null && !insuranceFees.isEmpty()) { // Insurance Fees
claim.setClInsuranceFee(new BigDecimal(insuranceFees));
}
if (registeredFees != null && !insuranceFees.isEmpty()) { // Registered Fees
claim.setClRegisteredFee(new BigDecimal(registeredFees));
}
if (codFees != null && !insuranceFees.isEmpty()) { // COD Fees
claim.setClCodFee(new BigDecimal(codFees));
}
claim.setClInsRegCodAmt(null);
错误:根据您的意见
Caused by: java.lang.NumberFormatException: Not a valid char constructor input:
at java.math.BigDecimal.bad(BigDecimal.java:1859)
at java.math.BigDecimal.charParser(BigDecimal.java:1303)
at java.math.BigDecimal.<init>(BigDecimal.java:922)
at java.math.BigDecimal.<init>(BigDecimal.java:901)
at gov.usps.oic.controller.OicClaimEntryControlloer.submitClaim(OicClaimEntryControlloer.java:991)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:60)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:37)
at java.lang.reflect.Method.invoke(Method.java:611)
at org.springframework.web.method.support.InvocableHandlerMethod.invoke(InvocableHandlerMethod.java:215)
at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:132)
at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:104)
at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandleMethod(RequestMappingHandlerAdapter.java:745)
at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:686)
at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:80)
at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:925)
at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:856)
at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:953)
你确定你传递通过解析在http://docs.oracle.com/ specced语法的字符串javase/7/docs/api/java/math/BigDecimal.html#BigDecimal(java.lang.String)? – jdphenix 2014-09-03 21:14:53
你能发布导致异常的输入字符串吗? – jdphenix 2014-09-03 21:22:51
我只是重申,前面的代码是addidng到我的输入字符串传递字符串是1.50美元。 – user2149910 2014-09-03 21:30:24