本文主要是介绍ava.lang.IllegalArgumentException: Cannot format given Object as a Date,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
org.apache.jasper.JasperException: Cannot format given Object as a Date
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:254)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:295)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:241)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
root cause
java.lang.IllegalArgumentException: Cannot format given Object as a Date
java.text.DateFormat.format(Unknown Source)
java.text.Format.format(Unknown Source)
com.lyang.governmentbill.CCI.jsp.Bean.ReportManagerBean.reportManagerBean(ReportManagerBean.java:115)
org.apache.jsp.reportList_jsp._jspService(reportList_jsp.java:141)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:137)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:210)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:295)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:241)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
note The full stack trace of the root cause is available in the Apache Tomcat/5.5.17 logs.
【异常处理】
Apache Tomcat/5.5.17
ReportManagerBean.java:115行代码如下:
String begin=sdf.format(begintime);
注:sdf为:SimpleDateFormat sdf=new SimpleDateFormat("yyyy年MM月dd日");
begintime 为:String begintime=request.getParameter("begintime");
传值是对象不是日期类型 将begintime 转化一下
将String begin=sdf.format(begintime); 改为:String begin=sdf.format(DateFormat.getDateInstance().parse(begintime)); 就好了。SimpleDateFormat 的format方法是:public final java.lang.String format(java.util,Date org0); format方法应该传一个Date类型的参数,而不是String 或者是其它的。
这篇关于ava.lang.IllegalArgumentException: Cannot format given Object as a Date的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!