Java 空指针异常

Java 空指针异常,java,Java,我在这个函数中遇到了一些问题,我遇到了空值并得到了一个空指针异常sqlDate和sqlTime为空 private void setCalendarComboDetails(Map tenantConnInfo, HttpSession session, HttpServletRequest request) { logger.info("Enter setCalendarComboDetails"); Appointment appointmentInfo = new App

我在这个函数中遇到了一些问题,我遇到了空值并得到了一个空指针异常
sqlDate
sqlTime
为空

 private void setCalendarComboDetails(Map tenantConnInfo, HttpSession session, HttpServletRequest request) {
    logger.info("Enter setCalendarComboDetails");
    Appointment appointmentInfo = new Appointment();
    Date sqlDate;
    Time sqlTime;

    try {
        CompanyDbImpl companyImpl = new CompanyDbImpl(tenantConnInfo);
        PatientDbImpl patientImpl = new PatientDbImpl(tenantConnInfo);
        DoctorDbImpl doctorImpl = new DoctorDbImpl(tenantConnInfo);

        CalendarDbImpl calendarImpl = new CalendarDbImpl(tenantConnInfo);
        ConfigurationDbImpl configurationImpl = new ConfigurationDbImpl(tenantConnInfo);
        session.setAttribute("isvalid",true);
        session.removeAttribute("appointmentInfo");
       // session.removeAttribute("index");
        List<CompanyBranchDetails> branchDetailsList = companyImpl.getCompanyNBranchList();
        session.setAttribute("companyBranchList", branchDetailsList);

        List<PatientInfo> patientList = patientImpl.getPatientInfoList();
        session.setAttribute("patientInfoList", patientList);

        String whereClause = " dbd.branch_id=" + branchDetailsList.get(0).getBranchId();

        List<DoctorBranchDetails> doctorBranchDetailsList = doctorImpl.getDoctorBranchDetailsListByWhereClause(whereClause);
        System.out.println("doctor branch list size " + doctorBranchDetailsList.size());
        session.setAttribute("doctorBranchList", doctorBranchDetailsList);

        Map configMap = configurationImpl.getConfigurationMapByConfigType(ApplicationConstants.CONFIGURATION_TYPE_CALENDAR);

        int timeFormatId = Integer.parseInt(configMap.get("time_format_id").toString());
        whereClause = " time_format_id=" + timeFormatId;
        String dbTimeFormat = calendarImpl.getTimeFormatListByWhereClause(whereClause).get(0).getTimeFormatType();

        int dateFormatId = Integer.parseInt(configMap.get("date_format_id").toString());
        whereClause = " date_format_id=" + dateFormatId;
        String dbDateFormat = calendarImpl.getDateFormatListByWhereClause(whereClause).get(0).getDateFormatType();
        session.setAttribute("calendarDateFormat", dbDateFormat);

        String jsStart = request.getParameter("start1");
        String jsEnd = request.getParameter("end1");
        String jsDateNTimeFormat = ApplicationConstants.JS_DATENTIME_PATTERN;
        System.out.println("start1 " + request.getParameter("start1") + " " + new java.util.Date());

        sqlDate = appointmentInfo.getStartDate().getDatepickerDate();
            appointmentInfo.setStrStartDate(ApplicationUtils.formatSqlDate(dbDateFormat, sqlDate));
        System.out.println("sqlDate1"+sqlDate);
          sqlTime = appointmentInfo.getStartTime().getTimepickerTime();
            appointmentInfo.setStrStartTime(ApplicationUtils.formatSqlTime(dbTimeFormat, sqlTime));
            java.util.Date date1 = ApplicationUtils.getDateFromSqlDateNTime(sqlDate, sqlTime);

            sqlDate = appointmentInfo.getEndDate().getDatepickerDate();
            appointmentInfo.setStrEndDate(ApplicationUtils.formatSqlDate(dbDateFormat, sqlDate));

            sqlTime = appointmentInfo.getEndTime().getTimepickerTime();
            appointmentInfo.setStrEndTime(ApplicationUtils.formatSqlTime(dbTimeFormat, sqlTime));

            java.util.Date date2 = ApplicationUtils.getDateFromSqlDateNTime(sqlDate, sqlTime);

            String diff = ApplicationUtils.getDateDifference(date1, date2);
            appointmentInfo.setDuration(diff);
            System.out.println("difference"+diff);
        if(session.getAttribute("index") != null) {
             doctorBranchDetailsList = (ArrayList<DoctorBranchDetails>)session.getAttribute("doctorBranchDetailsList");
            int selectedIndex = Integer.parseInt(session.getAttribute("index").toString());
        DoctorBranchDetails doctorBranchInfo = doctorBranchDetailsList.get(selectedIndex);           
        appointmentInfo.getDoctorBranchDetails().setDoctorBranchId(doctorBranchInfo.getDoctorBranchId());
        appointmentInfo.getDoctorBranchDetails().getCompanyBranchDetails().setBranchId(doctorBranchInfo.getCompanyBranchDetails().getBranchId());
        appointmentInfo.getDoctorBranchDetails().setDoctorName(doctorBranchInfo.getDoctorInfo().getFullName());
         appointmentInfo.getDoctorBranchDetails().setBranchNType(doctorBranchInfo.getBranchNType());           
        }

             appointmentInfo.setStrStartDate(ApplicationUtils.converDateFormats(jsStart, jsDateNTimeFormat, dbDateFormat));
        appointmentInfo.setStrStartTime(ApplicationUtils.converDateFormats(jsStart, jsDateNTimeFormat, dbTimeFormat));
        appointmentInfo.setStrEndDate(ApplicationUtils.converDateFormats(jsEnd, jsDateNTimeFormat, dbDateFormat));
        appointmentInfo.setStrEndTime(ApplicationUtils.converDateFormats(jsEnd, jsDateNTimeFormat, dbTimeFormat));

        session.setAttribute("appointmentInfo", appointmentInfo);
    } catch (Exception e) {
        logger.error(e, e);
    }
    logger.info("Exit setCalendarComboDetails");
}
private void setCalendarComboDetails(映射租户帐户信息、HttpSession会话、HttpServletRequest请求){
info(“输入setCalendarComboDetails”);
约会约会信息=新约会();
日期sqlDate;
时间;
试一试{
CompanyDbImpl companyImpl=新的CompanyDbImpl(租户信息);
PatientDbImpl patientImpl=新的PatientDbImpl(租户信息);
DoctorDbImpl doctorImpl=新DoctorDbImpl(租户信息);
CalendardImpl calendarImpl=新的CalendardImpl(租户通知);
ConfigurationDbImpl configurationImpl=新的ConfigurationDbImpl(租户帐户信息);
session.setAttribute(“isvalid”,true);
删除属性(“任命信息”);
//删除属性(“索引”);
List branchDetailList=companyImpl.getcompanyBranchList();
setAttribute(“companyBranchList”,BranchDetailList);
List patientList=patientImpl.getPatientFolist();
session.setAttribute(“patientInfoList”,patientList);
String whereClause=“dbd.branch_id=“+branchDetailsList.get(0.getBranchHid()”;
List doctorBranchDetailsList=doctorImpl.getDoctorBranchDetailsListByWhereClause(whereClause);
System.out.println(“医生分支列表大小”+doctorBranchDetailsList.size());
setAttribute(“doctorBranchList”,doctorBranchDetailsList);
Map configMap=configurationImpl.getConfigurationMapByConfigType(ApplicationConstants.CONFIGURATION\u TYPE\u日历);
int timeFormatId=Integer.parseInt(configMap.get(“time\u format\u id”).toString());
whereClause=“time\u format\u id=“+timeFormatId;
字符串dbTimeFormat=calendarImpl.getTimeFormatListByWhereClause(whereClause).get(0.getTimeFormatType();
int dateFormatId=Integer.parseInt(configMap.get(“date\u format\u id”).toString();
whereClause=“date\u format\u id=“+dateFormatId;
字符串dbDateFormat=calendarImpl.getDateFormatListByWhereClause(whereClause).get(0.getDateFormatType();
setAttribute(“calendarDateFormat”,dbDateFormat);
字符串jsStart=request.getParameter(“start1”);
字符串jsEnd=request.getParameter(“end1”);
字符串jsDateNTimeFormat=ApplicationConstants.JS_DATENTIME_模式;
System.out.println(“start1”+request.getParameter(“start1”)+“”+new java.util.Date());
sqlDate=AppointInfo.getStartDate().getDatepickerDate();
AppointInfo.setStrStartDate(ApplicationUtils.formatSqlDate(dbDateFormat,sqlDate));
System.out.println(“sqlDate1”+sqlDate);
sqlTime=AppointInfo.getStartTime().getTimepickerTime();
appointmentInfo.setStrStartTime(ApplicationUtils.formatSqlTime(dbTimeFormat,sqlTime));
java.util.Date date1=ApplicationUtils.getDateFromSqlDateNTime(sqlDate,sqlTime);
sqlDate=AppointInfo.getEndDate().getDatepickerDate();
AppointInfo.setStrEndDate(ApplicationUtils.formatSqlDate(dbDateFormat,sqlDate));
sqlTime=AppointInfo.getEndTime().getTimepickerTime();
appointmentInfo.setStrEndTime(ApplicationUtils.formatSqlTime(dbTimeFormat,sqlTime));
java.util.Date date2=ApplicationUtils.getDateFromSqlDateNTime(sqlDate,sqlTime);
String diff=ApplicationUtils.getDateDifference(date1,date2);
任命信息设置持续时间(差异);
系统输出打印项次(“差异”+diff);
if(session.getAttribute(“index”)!=null){
doctorBranchDetailsList=(ArrayList)session.getAttribute(“doctorBranchDetailsList”);
int selectedIndex=Integer.parseInt(session.getAttribute(“index”).toString());
DoctorBranchDetails doctorBranchInfo=doctorBranchDetailsList.get(selectedIndex);
appointmentInfo.getDoctorBranchDetails().setDoctorBranchId(doctorBranchInfo.getDoctorBranchId());
AppointInfo.getDoctorBranchDetails().getCompanyBranchDetails().setBranchId(doctorBranchInfo.getCompanyBranchDetails().getBranchId());
AppointInfo.getDoctorBranchDetails().setDoctorName(doctorBranchInfo.getDoctorInfo().getFullName());
appointmentInfo.getDoctorBranchDetails().setBranchNType(doctorBranchInfo.getBranchNType());
}
AppointInfo.setStrStartDate(ApplicationUtils.converDateFormats(jsStart、JSDateEntimeFormat、dbDateFormat));
appointmentInfo.setStrStartTime(ApplicationUtils.converDateFormats(jsStart、jsDateNTimeFormat、dbTimeFormat));
AppointInfo.setStrEndDate(ApplicationUtils.converDateFormats(jsEnd、jsDateNTimeFormat、dbDateFormat));
AppointInfo.setStrEndTime(ApplicationUtils.converDateFormats(jsEnd、jsDateNTimeFormat、dbTimeFormat));
session.setAttribute(“appointmentInfo”,appointmentInfo);
}捕获(例外e){
记录器错误(e,e);
}
logger.info(“Exit setCalendarComboDetails”);
}

学会调试。

你有很多工具可以使用。试试看。把这个弄清楚。如果你不能分解你的代码并发现问题,那么作为一个程序员,除了在小型应用程序上,你就没有什么用处了。此网站不是调试器的替代品。以下是一些你应该做的事情

  • 自己找出调试器,或者使用内置了这些函数的IDE,比如Eclipse。在函数的开始处设置断点并逐步执行。确保所有变量都包含在方法的每个步骤中所需的内容

  • 在代码中添加
    System.out.println()
    行,或者使用log4j之类的日志框架输出变量的内容。运行这部分代码后,请检查控制台并确保