2010-10-27 98 views
0

我得到解析异常,当我执行code.Can下面请人帮我出分析异常(无法解析的日期)

private Boolean validateDateFormat(HttpSession session, PropertiesHandler props, String startDate,Date sqlDate) { 
     logger.info("Enter validate"); 
     Boolean isvalid = true; 
     HashMap hashMap = new LinkedHashMap(); 
     System.out.println("Entered validate block"); 
     if (startDate == null || startDate.equals("")) { 
      isvalid = false; 
      hashMap.put("date", props.getText("error.date.compare.cannotbeblank")); 
      session.setAttribute("errorMessage", hashMap); 
      System.out.println("Map size " + hashMap.size()); 
      logger.info("Exit validate"); 
      return isvalid; 
     } 

     ArrayList<CalendarDatepicker> calList = new ArrayList<CalendarDatepicker>(); 
     String whereClause = " cd.calendar_datepicker="+sqlDate; 
     calList = (ArrayList<CalendarDatepicker>)dateTimePickerImpl.getCalendarDateDetailsByWhereClause(whereClause); 
     System.out.append("appointment list size " + calList.size()); 
     if(calList.isEmpty()) 
     { 
      isvalid=false; 
      System.out.println("here"); 
      hashMap.put("date", props.getText("error.date.compare.incorrectformat")); 
      session.setAttribute("errorMessage", hashMap); 
      System.out.println("Map size " + hashMap.size()); 
      logger.info("Exit validate"); 
      return isvalid; 
     } 
+0

行号,异常消息。 – 2010-10-27 15:50:55

+0

什么输入是窒息? – Oded 2010-10-27 15:53:32

+0

http://www.snapbuzz.com/image/17694/ – helpermethod 2010-10-27 15:53:44

回答

0

你在最后的评论中提到:其给空指针异常和异常解析如果我给10/00/2010或10/32/2010

呃......当然是这样。由于10/00/101010/32/2010都是有效日期,因此它会给您带来不可约日期例外。

究竟是你解析日期吗?你应该尝试在一个try-catch块周围:

try { 
    // parse date here 
} catch (ParseException e) { 
    // handle what do to on parse exception here 
} 

您可以选择设置一个默认的日期(如本月中旬)追赶时不可分析的日期,或者记录错误等