java.lang.NumberFormatException:对于输入字符串:“20110328094108069414”

前端之家收集整理的这篇文章主要介绍了java.lang.NumberFormatException:对于输入字符串:“20110328094108069414”前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

我试图将String值转换为long,并且得到:java.lang.NumberFormatException:对于输入字符串:“20110328094108069414”

我的代码

  String buyId  = "PSFT_20110328114728073793";
  long bookId  = Long.parseLong(buyId  .replaceAll("PSFT_",""));

错误

10:12:10,522 ERROR [STDERR] java.lang.NumberFormatException: For input string: "20110328094108069414"
10:12:10,522 ERROR [STDERR]     at java.lang.NumberFormatException.forInputString(NumberFormatException.java:48)
10:12:10,522 ERROR [STDERR]     at java.lang.Long.parseLong(Long.java:415)
10:12:10,522 ERROR [STDERR]     at java.lang.Long.parseLong(Long.java:461)
10:12:10,522 ERROR [STDERR]     at unilog.com.user.ejb.userDAOORCL.checkCWSUserReg(userDAOORCL.java:363)
10:12:10,522 ERROR [STDERR]     at unilog.com.user.ejb.userEJBBean.checkCWSUserReg(userEJBBean.java:141)
10:12:10,522 ERROR [STDERR]     at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
10:12:10,523 ERROR [STDERR]     at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
10:12:10,523 ERROR [STDERR]     at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
10:12:10,523 ERROR [STDERR]     at java.lang.reflect.Method.invoke(Method.java:585)
10:12:10,523 ERROR [STDERR]     at org.jboss.invocation.Invocation.performCall(Invocation.java:359)
10:12:10,523 ERROR [STDERR]     at org.jboss.ejb.StatelessSessionContainer$ContainerInterceptor.invoke(StatelessSessionContainer.java:237)
10:12:10,523 ERROR [STDERR]     at org.jboss.resource.connectionmanager.CachedConnectionInterceptor.invoke(CachedConnectionInterceptor.java:158)
最佳答案
我认为你需要使用BigIntegerBigDecimal

例如:

BigInteger bi;

String buyId  = "PSFT_20110328114728073793";
bi  = new BigInteger(buyId.replaceAll("PSFT_",""));

使用NumberFormatException添加try-catch块

猜你在找的Java相关文章