java.lang.NumberFormatException: For input stri...

最近做项目,出现一个错误,如下:
java.lang.NumberFormatException: For input string: "article"
at java.lang.NumberFormatException.forInputString(NumberFormatException.java:48)
at java.lang.Integer.parseInt(Integer.java:449)
at java.lang.Integer.parseInt(Integer.java:499)
at javax.el.ArrayELResolver.coerce(ArrayELResolver.java:161)
at javax.el.ArrayELResolver.getValue(ArrayELResolver.java:45)
at javax.el.CompositeELResolver.getValue(CompositeELResolver.java:54)
at org.apache.el.parser.AstValue.getValue(AstValue.java:123)
at org.apache.el.ValueExpressionImpl.getValue(ValueExpressionImpl.java:186)
at org.apache.jasper.runtime.PageContextImpl.proprietaryEvaluate(PageContextImpl.java:935)
at org.apache.jsp.personShow_jsp._jspx_meth_s_005fiterator_005f0(personShow_jsp.java:226)
at org.apache.jsp.personShow_jsp._jspService(personShow_jsp.java:178)
at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:377)
at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:313)
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:260)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:646)
at org.apache.catalina.core.ApplicationDispatcher.processRequest(ApplicationDispatcher.java:436)
at org.apache.catalina.core.ApplicationDispatcher.doForward(ApplicationDispatcher.java:374)
at org.apache.catalina.core.ApplicationDispatcher.forward(ApplicationDispatcher.java:302)
at org.apache.struts2.dispatcher.ServletDispatcherResult.doExecute(ServletDispatcherResult.java:139)
at org.apache.struts2.dispatcher.StrutsResultSupport.execute(StrutsResultSupport.java:178)
at com.opensymphony.xwork2.DefaultActionInvocation.executeResult(DefaultActionInvocation.java:348)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:253)
at com.opensymphony.xwork2.interceptor.DefaultWorkflowInterceptor.doIntercept(DefaultWorkflowInterceptor.java:221)
at com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:86)
at com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:224)
at com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:223)
at com.opensymphony.xwork2.util.profiling.UtilTimerStack.profile(UtilTimerStack.java:455)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:221)
at com.opensymphony.xwork2.validator.ValidationInterceptor.doIntercept(ValidationInterceptor.java:150)
at org.apache.struts2.interceptor.validation.AnnotationValidationInterceptor.doIntercept(AnnotationValidationInterceptor.java:48)
at com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:86)
at com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:224)
at com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:223)
at com.opensymphony.xwork2.util.profiling.UtilTimerStack.profile(UtilTimerStack.java:455)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:221)
at com.opensymphony.xwork2.interceptor.ConversionErrorInterceptor.intercept(ConversionErrorInterceptor.java:123)
at com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:224)
at com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:223)
at com.opensymphony.xwork2.util.profiling.UtilTimerStack.profile(UtilTimerStack.java:455)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:221)
......
花费了我好长时间,不过最后还是发现了问题所在,分享一下,希望能帮到大家。
action中方法代码:(注:generalService为通用service)
public String personShow() throws Exception{
person = (Person) generalService.findByProperty(Person.class, "id", personId).get(0);
String allCountSql = "SELECT count(id) FROM Doc where personId ='"+personId+"'";
String hql = "select * FROM doc where person_id = '"+personId+"' ORDER BY 'insertTime' DESC";
int allCount = ((Long)(generalService.find(allCountSql)).get(0)).intValue();
// docList = generalService.find(hql,page.start*10,10);
docList = generalService.executeSQL(hql);   //错误所在
page.setAllCount(allCount);
page.setStart(page.getStart());
return "personShow";
}
jsp中代码:
 <s:iterator value="docList" id="m" status="index">
                <table width="100%" >
<tr>
 <td colspan="4" align="left">${m.article}</td>
</tr>
<tr>
 <td width="25%" align="center">${m.insertTime}</td>
 <td width="25%" align="center">&nbsp;<a href="">${m.origin }</a></td>
 <td width="25%" align="center">&nbsp; ${m.transmit}</td>
 <td width="25%" align="center">&nbsp;${m.discuss}</td>
 </tr>
</table>
        </s:iterator>
此问题的主要是因为   generalService.executeSQL(hql)返回的list集合中的元素为object类型,没有转化为doc类对象,导致显示时找不到对应的article等。

转载于:https://my.oschina.net/u/225677/blog/83037

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
### 回答1: java.lang.NumberFormatExceptionJava程序中常见的异常类型之一,它的含义是字符串转换为数字时出现了错误。针对题目中的具体错误“for input string:”,通常情况下,这个错误提示是由于传入的字符串中包含了非数字字符,无法将其转换为数字。 例如,当我们尝试将字符串“abc123”转换为数字时,就会出现java.lang.NumberFormatException异常。这是因为该字符串中包含了字母“a”、“b”和“c”,无法转换为数字类型。 为了解决这个问题,我们需要在程序中添加判断语句,检查传入的字符串是否只包含数字字符,如果不是,则抛出异常并提示用户输入正确的数字。例如,可以使用Java中的isDigit方法来检查字符串中是否只包含数字字符。 总之,java.lang.NumberFormatException: for input string通常是由于传入的字符串包含非数字字符而引起的错误,需要进行有效的异常处理和输入验证来解决这个问题。 ### 回答2: java.lang.numberformatexception: for input string 是Java编程中常见的异常类型之一,它表示输入的数字格式不正确导致无法解析。 换句话说,这种异常会在使用一些方法(比如Integer.parseInt()或Double.parseDouble())将字符串转换为数字时发生,如果字符串的格式不正确,即使字符串包含数字字符,也会抛出此异常。 例如,如果一个字符串“abc123”被传递给Integer.parseInt()方法进行解析,就会抛出java.lang.numberformatexception: for input string:"abc123"异常,因为该方法无法将字符串"abc123"转换成整数类型。 为了避免这种异常的发生,开发者应该确保程序中传递给这些方法的字符串都是合法的数字格式。可以使用Java API提供的 regex 包的正则表达式或者其他符合业务需求的途径来检查数字格式是否正确。 此外,处理该异常还可以采取try-catch块来捕获,并在控制台或日志文件中输出相应的错误提示,以便后续进行排查。 ### 回答3: java.lang.numberformatexception: for input string: 是Java异常中的一种,通常当程序试图将一个字符串转换为数字或数字类型时抛出。这个异常的意思是输入的字符串不能被解释为一个有效的数字。 常见的引起这种异常的原因有以下几种: 1. 输入的字符串包含了非数字字符; 2. 输入的字符串过长,超出了解释器的处理范围; 3. 输入的字符串为空; 4. 输入的字符串超出了整型或浮点型的范围,无法转换为对应的类型; 5. 输入的字符串包含了科学计数法表示的数字,没有按照正确的格式输入。 只要在转换数字的时候,这些问题出现了其中之一,都会导致这种异常的出现。为了解决这个问题,我们可以做以下几件事情: 1. 检查输入的字符串是否正确,看看是否包含了非数字字符或超出了处理范围等问题; 2. 如果是科学计数法表示的数字,可以按照正确的格式输入; 3. 对于数字超过整型和浮点型的范围,我们可以使用 BigInteger 或 BigDecimal 进行处理; 4. 可以使用 try-catch 语句抓住异常,提示用户输入的数据格式错误。 因此,在处理字符串转数字的时候,我们需要特别小心,注意输入的格式和范围,以避免出现这种异常。同时,程序设计中要考虑用户输入数据的准确性和异常处理,以提高程序的稳定性和健壮性。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值