title: JasperReports: getting java.lang.ClassCastException: java.lang.String cannot be cast to java.lang.Number
body: <p>I am trying to generate excel reports from <em>Java</em>. I am using <em>Spring</em> on <em>Java</em> side and <em>iReport</em> to develop the jasper files. I am getting <code>ClassCast</code> exception although the report runs fine on <em>iReport</em>. The language I am using at <em>iReport</em> side for report is <em>Java</em>.</p>
  
  <p>The whole error Console is:</p>
  
  <pre><code>java.lang.ClassCastException: java.lang.String cannot be cast to java.lang.Number
      at net.sf.jasperreports.engine.JRAbstractExporter.getNumberCellValue(JRAbstractExporter.java:1198)
      at net.sf.jasperreports.engine.JRAbstractExporter.getTextValue(JRAbstractExporter.java:1139)
      at net.sf.jasperreports.engine.export.JRXlsExporter.createTextCell(JRXlsExporter.java:737)
      at net.sf.jasperreports.engine.export.JRXlsExporter.exportText(JRXlsExporter.java:684)
      at net.sf.jasperreports.engine.export.JRXlsAbstractExporter.exportPage(JRXlsAbstractExporter.java:1195)
      at net.sf.jasperreports.engine.export.JRXlsAbstractExporter.exportReportToStream(JRXlsAbstractExporter.java:940)
      at net.sf.jasperreports.engine.export.JRXlsAbstractExporter.exportReport(JRXlsAbstractExporter.java:629)
      at com.ultimatix.dao.SubmissionReportJasperDaoImpl.mainReportXLS(SubmissionReportJasperDaoImpl.java:590)
      at com.ultimatix.service.SubmissionReportJasperServiceImpl.excelDownload(SubmissionReportJasperServiceImpl.java:159)
  </code></pre>
  
  <p>Is there some mismatch of data types within the report or some other issue. Since <em>iReport</em> generates the o/p, I have no clue what is wrong at <em>Java</em> end.</p>
  
  <p>My Implementation: </p>
  
  <pre><code>    String mainDir="D:/Reports _ B_Type/";
  
          String[] sheetNames={"Contract Details","Quick Selection","Basic Details","Billing Related Parameter","Discounts Applicable","Charges Applicable","Other Parameter","Slab-Wise Rates"};
  
          Map&lt;String, Object&gt; parameters = new HashMap&lt;String, Object&gt;();
          contractId = (String) contractData.get(DBConstants.PROC_PI_CONTRACT_ID);
          versionNo = (String) contractData.get(DBConstants.VERSION_NO);
          String sql=SQLQuery.getCommonHeaderDetailForFCmVersion();
          ByteArrayOutputStream os1 = new ByteArrayOutputStream();
          try
          {
              jdbcTemplate = new JdbcTemplate(dataSource);
              contractDataList = jdbcTemplate.queryForList(sql,new Object[] {contractId,versionNo});
              for (Map&lt;String,Object&gt; row : contractDataList) {
                  contractingCompany=(String) row.get(DBConstants.FCM_CONTRACT_INFO_CONTRACTING_COMPANY);
                  customerName=(String) row.get(DBConstants.FCM_CONTRACT_INFO_MV_CUSTOMER_NAME);
                  startDate=(String) row.get(DBConstants.FCM_CONTRACT_INFO_MV_CONTRACT_START_DATE);
                  endDate=(String) row.get(DBConstants.FCM_CONTRACT_INFO_MV_CONTRACT_END_DATE);
                  if(null != row.get(DBConstants.FCM_CONTRACT_INFO_MV_TOTAL_CONTRACT_VALUE))
                  {   
                      tcsContractValue= row.get(DBConstants.FCM_CONTRACT_INFO_MV_TOTAL_CONTRACT_VALUE).toString();
                  }
                  contractStatus="E";
              }
  
              /*parameters to be passed in report */
  
              parameters.put("ContractId", contractId); 
              parameters.put("VersionNo", versionNo);
              parameters.put("SUBREPORT_DIR",mainDir);
              parameters.put("ContractingCompany",contractingCompany);
              parameters.put("CustomerName",customerName);
              parameters.put("StartDate",startDate);
              parameters.put("EndDate",endDate);
              parameters.put("TcsContractValue",tcsContractValue);
              parameters.put("ContractStatus",contractStatus);
  
              connection = DataSourceUtils.getConnection(dataSource);
  
              String reportTemplatePath = null;//path to find the template report
  
  
              String fileSep = File.pathSeparator;
  
              if(fileSep.equals(":") ){
  
              }else{
                  reportTemplatePath =mainDir + "Main Report.jasper";
              }
              JasperPrint jasperPrint;
  
                  jasperPrint = JasperFillManager.fillReport(
                          reportTemplatePath,parameters,connection);
  
              JRXlsExporter exporterXLS = new JRXlsExporter();
  
              exporterXLS.setParameter(JRXlsExporterParameter.JASPER_PRINT, jasperPrint);
  
              exporterXLS.setParameter(
                      JRXlsExporterParameter.IS_REMOVE_EMPTY_SPACE_BETWEEN_ROWS,Boolean.FALSE);
  
              exporterXLS.setParameter(JRXlsExporterParameter.IS_ONE_PAGE_PER_SHEET,
                      Boolean.TRUE);
              exporterXLS.setParameter(JRXlsExporterParameter.SHEET_NAMES,sheetNames);
              exporterXLS.setParameter(
                      JRXlsExporterParameter.IS_DETECT_CELL_TYPE, Boolean.TRUE);
              exporterXLS.setParameter(
                      JRXlsExporterParameter.IS_WHITE_PAGE_BACKGROUND, Boolean.TRUE);
              exporterXLS.setParameter(
                      JRXlsExporterParameter.CREATE_CUSTOM_PALETTE,Boolean.TRUE);//to generate closest matching color when report generated from java end.
  
  try{
              exporterXLS.setParameter(JRExporterParameter.OUTPUT_STREAM, os1);
              **exporterXLS.exportReport();**
  }
  catch(Exception e)
  {
      e.getMessage();
      e.printStackTrace();
  }`enter code here`
  </code></pre>
  
  <p>This is where i get the exception.</p>