开发者

parse exception (unparseable date)

开发者 https://www.devze.com 2023-01-22 01:31 出处:网络
I am getting parse exception when i execute the below code.Can anyone please help me out private Boolean validateDateFormat(HttpSession session, PropertiesHandler props, String startDate,Date sqlDate

I am getting parse exception when i execute the below code.Can anyone please help me out

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());
            log开发者_运维知识库ger.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;  
        }


You mentioned in the last comment : its giving null pointer exception and parse exception if i give 10/00/2010 or 10/32/2010.

Well ... of course it is. It is giving you an Unparsable Date exception because neither 10/00/1010 nor 10/32/2010 are valid dates.

Were exactly are you parsing the date? You should try surrounding it in a try-catch block:

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

You can choose to set a default date (e.g. the middle of the month) when catching an unparsable date, or log an error, etc.

0

精彩评论

暂无评论...
验证码 换一张
取 消