title: Why I do get "Value [null] cannot be converted to a JRDataSource" exception
body: <p>i'm trying to calculate number of admissions for particular year range input</p>
  
  <p>but why I do get this exception (Checked a few existing answers but couldn't figure it out.)</p>
  
  <pre><code>org.springframework.web.util.NestedServletException: Request processing failed; nested exception is java.lang.IllegalArgumentException: Value [null] cannot be converted to a JRDataSource
  </code></pre>
  
  <p>This is my controller </p>
  
  <pre><code>@RequestMapping(value ="/BMIbyage",method = RequestMethod.GET)
  public ModelAndView BMIbyage(ModelAndView modelAndView, ModelMap model, Map&lt;String, Object&gt; map,HttpServletRequest request,
          @RequestParam("syear") int syear,@RequestParam("eyear") int eyear,HttpSession session){
      String childid = (String) session.getAttribute("childid");
  
  
      List&lt;AdmissionSummery&gt; asum = new ArrayList&lt;AdmissionSummery&gt;();
  
       List&lt;PatientDetails&gt; patientdetail = patientService.listpatient();
  
      for(int i=syear;i&lt;=eyear;i++){
           asum.add(new AdmissionSummery());
          int no=0;
          for(int j=0;j&lt;patientdetail.size();j++){
  
  
              float bmi = patientService.listPatient(patientdetail.get(j).getChildid()).get(0).getBmi();
  
  
              if(bmi&lt;18.5){
                  no=no+1;
  
                  asum.get(asum.size()-1).setNooftime(no);
  
              }
              System.out.println("no"+no);
              System.out.println("j"+j);
              asum.get(asum.size()-1).setDuration(syear+" "+"-"+" "+eyear);
              asum.get(asum.size()-1).setYear(i);
  
              System.out.println("BMI"+bmi);
  
          }
  
  
  
          System.out.println("i"+i);
      }
  
        JRDataSource datasource = new JRBeanCollectionDataSource(asum);   
  
          model.addAttribute("datasourcebmireportA", datasource);
  
          model.addAttribute("format", "pdf");
  
          modelAndView = new ModelAndView("pdfReportViewaddsummeryA", model);
  
  
  
      return modelAndView;
  
  
  }
  </code></pre>
  
  <p>here is the jsp</p>
  
  <pre><code>&lt;tr&gt;
      &lt;td  &gt;&lt;a href="#"&gt;&lt;div class="box"&gt;
          &lt;form action="BMIbyage"&gt;
          &lt;table width="584"&gt;
          &lt;tr&gt;
          &lt;td width="172"&gt;
          &lt;font color="black"&gt;BMI value  18.5kg/m2&lt;/font&gt;&lt;/td&gt;
          &lt;td width="82"&gt;
      &lt;select name="syear"&gt; 
      &lt;option value="Pleaseselect"&gt;----&lt;/option&gt;
                  &lt;%for(int j=1980;j&lt;=2030;j++)
                  {
                      %&gt;
                      &lt;option value="&lt;%=j%&gt;"&gt;&lt;%=j%&gt;&lt;/option&gt;
                      &lt;%
                      }
                      %&gt;
      &lt;/select&gt;
      &lt;/td&gt;
      &lt;td width="20"&gt; to &lt;/td&gt;
  
      &lt;td width="178"&gt;
      &lt;select name="eyear"&gt; 
      &lt;option value="Pleaseselect"&gt;----&lt;/option&gt;
                  &lt;%for(int j=1980;j&lt;=2030;j++)
                  {
                      %&gt;
                      &lt;option value="&lt;%=j%&gt;"&gt;&lt;%=j%&gt;&lt;/option&gt;
                      &lt;%
                      }
                      %&gt;
      &lt;/select&gt;
      &lt;/td&gt;
      &lt;td width="108"&gt;&lt;input type="submit" value="Generate"&gt;&lt;/td&gt;
      &lt;/tr&gt;
      &lt;/table&gt;
          &lt;/form&gt;
  
      &lt;/div&gt;&lt;/a&gt;&lt;/td&gt;
      &lt;/tr&gt;
  </code></pre>
  
  <p>and this is the jasper-views.xml</p>
  
  <pre><code>&lt;bean id="pdfReportViewaddsummeryA" class="org.springframework.web.servlet.view.jasperreports.JasperReportsMultiFormatView" p:url="/WEB-INF/Reports/BMIReport.jasper" p:reportDataKey="datasourceadmissionreportA" /&gt;
  </code></pre>