Error in creating chart

0

While creating chart from java bean i am gettting error 

----------------------------------------------------------------------------------------

Error

----------------------------------------------------------------------------------------

net.sf.jasperreports.engine.JRException: Error retrieving field value from bean : subjectName
at net.sf.jasperreports.engine.data.JRAbstractBeanDataSource.getBeanProperty(JRAbstractBeanDataSource.java:123)
at net.sf.jasperreports.engine.data.JRAbstractBeanDataSource.getFieldValue(JRAbstractBeanDataSource.java:96)
at net.sf.jasperreports.engine.data.JRBeanCollectionDataSource.getFieldValue(JRBeanCollectionDataSource.java:100)
at net.sf.jasperreports.engine.fill.JRFillDataset.setOldValues(JRFillDataset.java:1330)
at net.sf.jasperreports.engine.fill.JRFillDataset.next(JRFillDataset.java:1231)
at net.sf.jasperreports.engine.fill.JRFillDataset.next(JRFillDataset.java:1207)
at net.sf.jasperreports.engine.fill.JRBaseFiller.next(JRBaseFiller.java:1544)
at net.sf.jasperreports.engine.fill.JRVerticalFiller.fillReport(JRVerticalFiller.java:142)
at net.sf.jasperreports.engine.fill.JRBaseFiller.fill(JRBaseFiller.java:909)
at net.sf.jasperreports.engine.fill.JRBaseFiller.fill(JRBaseFiller.java:841)
at net.sf.jasperreports.engine.fill.JRFiller.fill(JRFiller.java:88)
at net.sf.jasperreports.engine.JasperFillManager.fill(JasperFillManager.java:653)
at net.sf.jasperreports.engine.JasperFillManager.fill(JasperFillManager.java:569)
at net.sf.jasperreports.engine.JasperFillManager.fillReport(JasperFillManager.java:915)
at ReportUtil.createReport(ReportUtil.java:33)
at ReportUtil.createReport(ReportUtil.java:51)
at Test.main(Test.java:18)
Caused by: java.lang.NoSuchMethodException: Unknown property 'subjectName'
at org.apache.commons.beanutils.PropertyUtilsBean.getSimpleProperty(PropertyUtilsBean.java:1122)
at org.apache.commons.beanutils.PropertyUtilsBean.getNestedProperty(PropertyUtilsBean.java:686)
at org.apache.commons.beanutils.PropertyUtilsBean.getProperty(PropertyUtilsBean.java:715)
at org.apache.commons.beanutils.PropertyUtils.getProperty(PropertyUtils.java:290)
at net.sf.jasperreports.engine.data.JRAbstractBeanDataSource.getBeanProperty(JRAbstractBeanDataSource.java:111)
... 16 more
----------------------------------------------------------------------------------------
Java code
----------------------------------------------------------------------------------------
public class JasperReportFill {
 
public static void main(String[] args) {
String sourceFileName = "D:/RetailApp/JasperFiles/spider.jasper";
 
DataBeanList DataBeanList = new DataBeanList();
ArrayList<DataBean> dataList = DataBeanList.getDataBeanList();
 
JRBeanCollectionDataSource beanColDataSource = new JRBeanCollectionDataSource(
dataList);
 
Map parameters = new HashMap();
 
try {
 
createReport(parameters, dataList);
JasperFillManager.fillReportToFile(sourceFileName, parameters,
beanColDataSource);
} catch (JRException e) {
e.printStackTrace();
}
}
 
public static void createReport(Map parameters, Collection data) {
String jasperFileName = "spider.jasper";
String pdfFileName = "Rep";
String jasperFullPath = "D:/RetailApp/JasperFiles/" + jasperFileName;
String pdfDir = "D:/RetailApp/PDF/";
 
File pdfPath = new File(pdfDir);
pdfPath.mkdirs();
 
File pdfFile = new File(pdfPath, pdfFileName);
String pdfFullPath = pdfFile.getAbsolutePath();
System.out.println(jasperFullPath);
try {
JRPdfExporter pdfExporter = new JRPdfExporter();
JasperPrint jasperPrint = null;
JRDataSource dataSource = new JRBeanCollectionDataSource(data);
jasperPrint = JasperFillManager.fillReport(jasperFullPath,
parameters, dataSource);
 
pdfExporter = new JRPdfExporter();
pdfExporter.setParameter(JRExporterParameter.JASPER_PRINT,
jasperPrint);
pdfExporter.setParameter(JRExporterParameter.OUTPUT_FILE_NAME,
pdfFullPath);
pdfExporter.exportReport();
 
} catch (Exception e) {
e.printStackTrace();
}
 
}
}
 
------------------------------------------------------------------------------------------------
DataBean class
------------------------------------------------------------------------------------------------
public class DataBeanList {
  public ArrayList getDataBeanList() {
     ArrayList dataBeanList = new ArrayList();
 
     dataBeanList.add(produce("English", 58));
     dataBeanList.add(produce("SocialStudies", 68));
     dataBeanList.add(produce("Maths", 38));
     dataBeanList.add(produce("Hindi", 88));
     dataBeanList.add(produce("Scince", 78));
     return dataBeanList;
  }
 
  /*
   * This method returns a DataBean object, with subjectName ,
   * and marks set in it.
   */
  private DataBean produce(String subjectName, Integer marks) {
     DataBean dataBean = new DataBean();
 
     dataBean.setSubjectName(subjectName);
     dataBean.setMarks(marks);
 
     return dataBean;
  }
}
----------------------------------------------------------------------------------------------------
POJO
_________________________________________________________
public class DataBean {
  public String subjectName;
  public Integer marks;
 
  public String getSubjectName() {
     return subjectName;
  }
 
  public void setSubjectName(String subjectName) {
     this.subjectName = subjectName;
  }
 
  public Integer getMarks() {
     return marks;
  }
 
  public void setMarks(Integer marks) {
     this.marks = marks;
  }
 
}
----------------------------------------------------------------------------------------------------
JRXML
----------------------------------------------------------------------------------------------------
<?xml version="1.0" encoding="UTF-8"?>
<jasperReport xmlns="http://jasperreports.sourceforge.net/jasperreports" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://jasperreports.sourceforge.net/jasperreports http://jasperreports.sourceforge.net/xsd/jasperreport.xsd" name="spider" language="groovy" pageWidth="595" pageHeight="842" columnWidth="555" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20" uuid="1e6a951a-42b2-4a58-a471-bc6b0aa60e96">
<property name="ireport.zoom" value="1.0"/>
<property name="ireport.x" value="0"/>
<property name="ireport.y" value="0"/>
<field name="subjectName" class="java.lang.String"/>
<field name="marks" class="java.lang.Number"/>
<background>
<band splitType="Stretch"/>
</background>
<title>
<band height="79" splitType="Stretch"/>
</title>
<pageHeader>
<band height="35" splitType="Stretch"/>
</pageHeader>
<columnHeader>
<band height="61" splitType="Stretch"/>
</columnHeader>
<detail>
<band height="204" splitType="Stretch">
<barChart>
<chart>
<reportElement x="57" y="64" width="200" height="100" uuid="94df4b9b-1fb1-4360-9db9-9ab4a7d106fc"/>
<chartTitle/>
<chartSubtitle/>
<chartLegend/>
</chart>
<categoryDataset>
<categorySeries>
<seriesExpression><![CDATA[$F{subjectName}]]></seriesExpression>
<categoryExpression><![CDATA[$F{subjectName}]]></categoryExpression>
<valueExpression><![CDATA[$F{marks}]]></valueExpression>
</categorySeries>
</categoryDataset>
<barPlot>
<plot/>
<itemLabel/>
<categoryAxisFormat>
<axisFormat/>
</categoryAxisFormat>
<valueAxisFormat>
<axisFormat/>
</valueAxisFormat>
</barPlot>
</barChart>
</band>
</detail>
<columnFooter>
<band height="45" splitType="Stretch"/>
</columnFooter>
<pageFooter>
<band height="54" splitType="Stretch"/>
</pageFooter>
<summary>
<band height="42" splitType="Stretch"/>
</summary>
</jasperReport>
 
 
tejas.chougule's picture
Joined: Apr 23 2014 - 3:15am
Last seen: 5 years 5 months ago

0 Answers:

No answers yet
Feedback
randomness