- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
表格字段
Field: Bank_Account_No
Type : int(100)
这是我的“帐户”模型,带有 setter/getter 方法
@Entity
@Table(name = "account")
public class Account {
@Column(name = "Pharmacy_Account_No")
private Integer pharmacyAccountNo;
public Integer getPharmacyAccountNo() {
return pharmacyAccountNo;
}
public void setPharmacyAccountNo(Integer pharmacyAccountNo) {
this.pharmacyAccountNo = pharmacyAccountNo;
}
}
如果我插入“1234567891”,它将成功添加。但是当我插入“123456789111111”时它会抛出 NumberFormatException
Inserting Code:
pharmacyAccount.setPharmacyAccountNo(request.getParameter("pharmacyAccountNo"). != null
&& !request.getParameter("pharmacyAccountNo").equals("")
? Integer.valueOf(request.getParameter("pharmacyAccountNo") : 0);
这里是 StackTrach:
java.lang.NumberFormatException: For input string: "123456789111111"
at java.lang.NumberFormatException.forInputString(Unknown Source)
at java.lang.Integer.parseInt(Unknown Source)
at java.lang.Integer.parseInt(Unknown Source)
at com.pharmacy.ServiceImpl.PharmacyServiceImpl.savePharmacyAccount(PharmacyServiceImpl.java:977)
at com.pharmacy.ServiceImpl.PharmacyServiceImpl.savePharmacy(PharmacyServiceImpl.java:838)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:307)
at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:183)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:150)
at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:108)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:202)
at com.sun.proxy.$Proxy29.savePharmacy(Unknown Source)
at com.pharmacy.Controller.PharmacyController.savePharmacy(PharmacyController.java:232)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.springframework.web.bind.annotation.support.HandlerMethodInvoker.doInvokeMethod(HandlerMethodInvoker.java:710)
at org.springframework.web.bind.annotation.support.HandlerMethodInvoker.invokeHandlerMethod(HandlerMethodInvoker.java:167)
at org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter.invokeHandlerMethod(AnnotationMethodHandlerAdapter.java:414)
at org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter.handle(AnnotationMethodHandlerAdapter.java:402)
at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:771)
at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:716)
at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:647)
at org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:563)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:650)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:731)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:303)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:343)
at org.springframework.security.web.access.intercept.FilterSecurityInterceptor.invoke(FilterSecurityInterceptor.java:99)
at org.springframework.security.web.access.intercept.FilterSecurityInterceptor.doFilter(FilterSecurityInterceptor.java:83)
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:355)
at org.springframework.security.web.access.intercept.FilterSecurityInterceptor.invoke(FilterSecurityInterceptor.java:109)
at org.springframework.security.web.access.intercept.FilterSecurityInterceptor.doFilter(FilterSecurityInterceptor.java:83)
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:355)
at org.springframework.security.web.access.ExceptionTranslationFilter.doFilter(ExceptionTranslationFilter.java:97)
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:355)
at org.springframework.security.web.session.SessionManagementFilter.doFilter(SessionManagementFilter.java:100)
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:355)
at org.springframework.security.web.authentication.AnonymousAuthenticationFilter.doFilter(AnonymousAuthenticationFilter.java:78)
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:355)
at org.springframework.security.web.servletapi.SecurityContextHolderAwareRequestFilter.doFilter(SecurityContextHolderAwareRequestFilter.java:54)
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:355)
at org.springframework.security.web.savedrequest.RequestCacheAwareFilter.doFilter(RequestCacheAwareFilter.java:35)
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:355)
at org.springframework.security.web.authentication.www.BasicAuthenticationFilter.doFilter(BasicAuthenticationFilter.java:177)
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:355)
at org.springframework.security.web.authentication.ui.DefaultLoginPageGeneratingFilter.doFilter(DefaultLoginPageGeneratingFilter.java:90)
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:355)
at org.springframework.security.web.authentication.AbstractAuthenticationProcessingFilter.doFilter(AbstractAuthenticationProcessingFilter.java:188)
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:355)
at org.springframework.security.web.authentication.AbstractAuthenticationProcessingFilter.doFilter(AbstractAuthenticationProcessingFilter.java:188)
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:355)
at org.springframework.security.web.authentication.logout.LogoutFilter.doFilter(LogoutFilter.java:105)
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:355)
at org.springframework.security.web.authentication.logout.LogoutFilter.doFilter(LogoutFilter.java:105)
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:355)
at org.springframework.security.web.context.SecurityContextPersistenceFilter.doFilter(SecurityContextPersistenceFilter.java:79)
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:355)
at org.springframework.security.web.session.ConcurrentSessionFilter.doFilter(ConcurrentSessionFilter.java:109)
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:355)
at org.springframework.security.web.FilterChainProxy.doFilter(FilterChainProxy.java:149)
at org.springframework.web.filter.DelegatingFilterProxy.invokeDelegate(DelegatingFilterProxy.java:237)
at org.springframework.web.filter.DelegatingFilterProxy.doFilter(DelegatingFilterProxy.java:167)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:220)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:122)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:505)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:170)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:103)
at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:956)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:116)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:423)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1079)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:625)
at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:318)
at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
at java.lang.Thread.run(Unknown Source)
最佳答案
如果查看堆栈跟踪,您会看到 java.lang.Integer.parseInt
您提供的数字太大,超出了整数范围。您应该尝试使用 Long
。
如果您查看 oracle 网站上的文档:
int: By default, the int data type is a 32-bit signed two's complement integer, which has a minimum value of -231 and a maximum value of 231-1. In Java SE 8 and later, you can use the int data type to represent an unsigned 32-bit integer, which has a minimum value of 0 and a maximum value of 232-1. Use the Integer class to use int data type as an unsigned integer. See the section The Number Classes for more information. Static methods like compareUnsigned, divideUnsigned etc have been added to the Integer class to support the arithmetic operations for unsigned integers.
来源:https://docs.oracle.com/javase/tutorial/java/nutsandbolts/datatypes.html
关于java - Java中如何解决NumberFormatException?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35502788/
我正在尝试使用 Integer.parseInt(simNumber) 将 String 转换为 int,但我收到错误消息。如何将 String 转换为 int?我在网上搜索了一下,找到了Intege
每次我尝试启动我的代码时,我总是遇到同样的错误: java.lang.NumberFormatException: For input string: "x" at java.lang.Numbe
在检查我的错误处理代码时偶然发现了这个。当您调用 Integer.parseInt(null) 时,Java 抛出 NumberFormatException 而 Float.parseFloat(n
如果有人可以看看我在 Selenium 方面遇到的问题。我尝试使用以下方法访问上述计算器中的结果: public String getAttributeValue(WebElement element
嗯,我很无聊,所以我想做一个二进制>十进制转换器。我将转换器的上限设置为 30 位数字 (1073741823) 或 (0111111111111111111111111111111)。我遇到的问题是
在以下代码中,Clojure (1.2) 打印出错误消息: (try (let [value "1,a"] (map #(Integer/parseInt %) (.split value
String str="123456.7855456677"; ParsePosition parsePosition = new ParsePosition(0); NumberFormat num
代码: String myVar = "1255763710960"; int myTempVar=0; try { myTempVar = Integer.valueOf(myVar); }
我在NumberFormatException代码中收到Grails错误,该错误是将电影分类到数据库中。该错误表明它来自cron插件。我已经完成了研究,并且一直在尝试使用NumberFormatExc
我在将字符串解析为原语时遇到问题。 File file1 = new File("bankData.txt"); Scanner sc = new Scanner(fi
所以我试图从日期列表中查找最新日期,但我不断收到 NumberFormatException。有什么办法可以解决这个问题吗? import java.util.*; public class Date
如果使用变量 bin1 它不会转换,但是如果我用 bin2 替换参数,它似乎可以工作。 我尝试使用 long 而不是 int。还是一样。 public class Test{ public s
我正在尝试找出如何在代码中捕获数字格式异常错误,这样如果用户在字符串中输入字母并且我的程序尝试将其解析为 int 我的程序将不会抛出错误而是停止并返回一个 boolean 值。我还试图了解,如果 tr
该程序的本质目的是将学生信息写入文件并从同一文件中读取。该程序包括一个 if 语句,用于判断学生是否处于良好信誉或留校察看状态,每个语句都有各自的文件(goodstand.txt 和 probatio
我正在用 Python/WLST 编写代码,以自动连接、启动和停止 weblogic 中的托管服务器。当我启动 Python 时,出现以下错误。 异常的含义是什么?我该如何解决它? Initializ
这是我的代码: public void setAreaAccessPoints(){ String mac = "",essid = "",status = ""; int stre
我正在用 Java 开发一个应用程序,发现了这个奇怪的行为: 如果通过控制面板将区域设置格式设置为匈牙利语(系统默认值),我会收到此异常,但如果我将其设置为英语格式,则它可以正常工作。也适用于虚拟 M
我正在尝试制作一个计算器应用程序,但不幸的是我无法解析字符串。 应用程序接受输入并将其显示在 EditText et2 中。当按下“等于”键时,计算器将执行以下工作。 et2 = (EditText)
我有一个文件,其中包含许多电影标题及其年份、5 星评级和长度。我正在尝试读取该文件并将标题、年份、评级和长度存储为变量。我遇到的问题是在我的检索年份的代码中。该代码可以编译,但在运行时,当它到达具有多
我正在解决亚马逊 Interview Street 网站上的 Connected Sets 问题 https://amazon.interviewstreet.com/challenges我的代码对于
我是一名优秀的程序员,十分优秀!