2013-08-16 75 views
0

我想,以填補一個數據源的報告,我得到這個異常:JRBeanCollectionDataSource - 未知屬性的類「NOTAS「類model.Notas」

Exception in thread "main" net.sf.jasperreports.engine.JRException: Error retrieving field value from bean : notas 
    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:1331) 
    at net.sf.jasperreports.engine.fill.JRFillDataset.next(JRFillDataset.java:1232) 
    at net.sf.jasperreports.engine.fill.JRFillDataset.next(JRFillDataset.java:1208) 
    at net.sf.jasperreports.engine.fill.JRBaseFiller.next(JRBaseFiller.java:1577) 
    at net.sf.jasperreports.engine.fill.JRVerticalFiller.fillReport(JRVerticalFiller.java:149) 
    at net.sf.jasperreports.engine.fill.JRBaseFiller.fill(JRBaseFiller.java:932) 
    at net.sf.jasperreports.engine.fill.JRBaseFiller.fill(JRBaseFiller.java:864) 
    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 NewMain.generarNotas(NewMain.java:38) 
    at NewMain.main(NewMain.java:66) 
Caused by: java.lang.NoSuchMethodException: Unknown property 'notas' on class 'class model.Notas' 
    at org.apache.commons.beanutils.PropertyUtilsBean.getSimpleProperty(PropertyUtilsBean.java:1322) 
    at org.apache.commons.beanutils.PropertyUtilsBean.getNestedProperty(PropertyUtilsBean.java:770) 
    at org.apache.commons.beanutils.PropertyUtilsBean.getProperty(PropertyUtilsBean.java:846) 
    at org.apache.commons.beanutils.PropertyUtils.getProperty(PropertyUtils.java:426) 
    at net.sf.jasperreports.engine.data.JRAbstractBeanDataSource.getBeanProperty(JRAbstractBeanDataSource.java:111) 
    ... 15 more 

這是我的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="report name" pageWidth="595" pageHeight="842" columnWidth="535" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20" uuid="020115f1-3bfe-4a04-bd2a-4167b98b9732"> 
    <property name="ireport.zoom" value="1.0000000000000004"/> 
    <property name="ireport.x" value="0"/> 
    <property name="ireport.y" value="0"/> 
    <subDataset name="notasDS" uuid="50c79efe-5519-47b6-ad00-c2f0e7ee7c09"> 
     <queryString> 
      <![CDATA[]]> 
     </queryString> 
     <field name="descripcionUsuario" class="java.lang.String"> 
      <fieldDescription><![CDATA[descripcionUsuario]]></fieldDescription> 
     </field> 
     <field name="descripcionNota" class="java.lang.String"> 
      <fieldDescription><![CDATA[descripcionNota]]></fieldDescription> 
     </field> 
     <field name="fechaDeRegistro" class="java.lang.String"> 
      <fieldDescription><![CDATA[fechaDeRegistro]]></fieldDescription> 
     </field> 
    </subDataset> 
    <field name="notas" class="java.util.Collection"/> 
    <background> 
     <band splitType="Stretch"/> 
    </background> 
    <title> 
     <band height="37" splitType="Stretch"> 
      <staticText> 
       <reportElement uuid="ef4eae36-66dd-4e97-be61-65e6dd13b896" x="0" y="0" width="555" height="35"/> 
       <textElement textAlignment="Center" verticalAlignment="Middle"> 
        <font fontName="Arial Black" size="24" isBold="true"/> 
       </textElement> 
       <text><![CDATA[NOTAS]]></text> 
      </staticText> 
     </band> 
    </title> 
    <pageHeader> 
     <band splitType="Stretch"/> 
    </pageHeader> 
    <columnHeader> 
     <band height="26" splitType="Stretch"> 
      <staticText> 
       <reportElement uuid="97256cf0-c9fe-4422-99aa-bbbb81232db3" x="2" y="1" width="100" height="20"/> 
       <textElement/> 
       <text><![CDATA[fechaDeRegistro]]></text> 
      </staticText> 
      <staticText> 
       <reportElement uuid="065b2f0c-afbd-4110-ba24-054f60994e6a" x="102" y="1" width="237" height="20"/> 
       <textElement/> 
       <text><![CDATA[descripcionNota]]></text> 
      </staticText> 
      <staticText> 
       <reportElement uuid="0add16bc-37b7-40e2-ab6d-8b2933b73cf8" x="339" y="1" width="216" height="20"/> 
       <textElement/> 
       <text><![CDATA[descripcionUsuario]]></text> 
      </staticText> 
     </band> 
    </columnHeader> 
    <detail> 
     <band height="21" splitType="Stretch"> 
      <componentElement> 
       <reportElement uuid="5fc40798-8e9a-4d07-b273-acc91b4147ec" x="0" y="0" width="555" height="21"/> 
       <jr:list xmlns:jr="http://jasperreports.sourceforge.net/jasperreports/components" xsi:schemaLocation="http://jasperreports.sourceforge.net/jasperreports/components http://jasperreports.sourceforge.net/xsd/components.xsd" printOrder="Vertical"> 
        <datasetRun subDataset="notasDS" uuid="98a1a836-2fc0-42e2-9ada-f3eea1c4ecba"> 
         <dataSourceExpression><![CDATA[new net.sf.jasperreports.engine.data.JRBeanCollectionDataSource($F{notas})]]></dataSourceExpression> 
        </datasetRun> 
        <jr:listContents height="21" width="555"> 
         <textField> 
          <reportElement uuid="d95ff7e4-4075-47be-b742-69af661799b6" x="2" y="1" width="100" height="20"/> 
          <textElement/> 
          <textFieldExpression><![CDATA[$F{fechaDeRegistro}]]></textFieldExpression> 
         </textField> 
         <textField> 
          <reportElement uuid="5a6e3c78-7d57-4f8d-8e5e-bc34e0740b1c" x="102" y="1" width="237" height="20"/> 
          <textElement/> 
          <textFieldExpression><![CDATA[$F{descripcionNota}]]></textFieldExpression> 
         </textField> 
         <textField> 
          <reportElement uuid="514ec211-8001-4201-bdd8-78d6d533315b" x="339" y="1" width="216" height="20"/> 
          <textElement/> 
          <textFieldExpression><![CDATA[$F{descripcionUsuario}]]></textFieldExpression> 
         </textField> 
        </jr:listContents> 
       </jr:list> 
      </componentElement> 
     </band> 
    </detail> 
    <columnFooter> 
     <band splitType="Stretch"/> 
    </columnFooter> 
    <pageFooter> 
     <band splitType="Stretch"/> 
    </pageFooter> 
    <summary> 
     <band splitType="Stretch"/> 
    </summary> 
</jasperReport> 

這是類我試圖通過

package model; 
import java.io.Serializable; 

public class Notas implements Serializable { 
    private static final long serialVersionUID = 48L; 
    private Integer codNota; 
    private String descripcionNota; 
    private String descripcionUsuario; 
    private String fechaDeRegistro; 
    private Boolean notForDelete; 
    private Boolean descripcionUsuarioMandatory = Boolean.FALSE; 

    public Notas() { 
    } 
    public Notas(Integer codNota) { 
     this.codNota = codNota; 
    } 
    public Notas(Integer codNota, String descripcionNota, String descripcionUsuario, String fechaDeRegistro) { 
     this.codNota = codNota; 
     this.descripcionNota = descripcionNota; 
     this.descripcionUsuario = descripcionUsuario; 
     this.fechaDeRegistro = fechaDeRegistro; 
     this.notForDelete = Boolean.FALSE; 
     this.descripcionUsuarioMandatory = Boolean.FALSE; 
    } 

    public Notas getMe() { 
     return this; 
    } 

    public Integer getCodNota() { 
     return codNota; 
    } 

    public void setCodNota(Integer codNota) { 
     this.codNota = codNota; 
    } 

    public String getDescripcionNota() { 
     return descripcionNota; 
    } 

    public void setDescripcionNota(String descripcionNota) { 
     this.descripcionNota = descripcionNota; 
    } 

    public String getDescripcionUsuario() { 
     return descripcionUsuario; 
    } 

    public void setDescripcionUsuario(String descripcionUsuario) { 
     this.descripcionUsuario = descripcionUsuario; 
    } 

    public String getFechaDeRegistro() { 
     return fechaDeRegistro; 
    } 

    public void setFechaDeRegistro(String fechaDeRegistro) { 
     this.fechaDeRegistro = fechaDeRegistro; 
    } 

    @Override 
    public int hashCode() { 
     int hash = 0; 
     hash += (codNota != null ? codNota.hashCode() : 0); 
     return hash; 
    } 

    @Override 
    public boolean equals(Object object) { 
     // TODO: Warning - this method won't work in the case the id fields are not set 
     if (!(object instanceof Notas)) { 
      return false; 
     } 
     Notas other = (Notas) object; 
     if ((this.codNota == null && other.codNota != null) 
       || (this.codNota != null && !this.codNota.equals(other.codNota)) 
       || (this.descripcionUsuario == null && other.descripcionUsuario != null) 
       || (this.descripcionUsuario != null && !this.descripcionUsuario.equals(other.descripcionUsuario))) { 
      return false; 
     } 
     return true; 
    } 

    @Override 
    public String toString() { 
     return "co.gov.rnec.srcw.model.Notas[ codNota=" + codNota + " ]"; 
    } 

    public Boolean getNotForDelete() { 
     return notForDelete; 
    } 

    public void setNotForDelete(Boolean notForDelete) { 
     this.notForDelete = notForDelete; 
    } 

    public Boolean getDescripcionUsuarioMandatory() { 
     return descripcionUsuarioMandatory; 
    } 

    public void setDescripcionUsuarioMandatory(Boolean descripcionUsuarioMandatory) { 
     this.descripcionUsuarioMandatory = descripcionUsuarioMandatory; 
    } 
} 

這也是我如何通過豆

List notas = Arrays.asList(
    new Notas(new Integer("1"), "CORRECCION", "DE nombre", "24/01/2013"), 
    new Notas(new Integer("5"), "SERIAL", "Cancelado", "25/12/2012"), 
    new Notas(new Integer("6"), "CAMBIOS", "En los nombres", "26/10/2012"), 
    new Notas(new Integer("7"), "DECRETO", "8", "27/12/2012") 
); 

Map parameters = new HashMap(); 
parameters.put("ReportTitle", "Notas"); 
parameters.put("DataFile", "Notas.java - Bean Collection"); 

JasperPrint jasperPrint = JasperFillManager.fillReport("Notas.jasper", 
     parameters, new JRBeanCollectionDataSource(notas, false)); 

JasperExportManager.exportReportToPdfFile(jasperPrint, "D:\\Notas.pdf"); 

報告的收集唯一的「NOTAS」我已經是數據源中的字段。

有人可以解決它嗎?

感謝

+0

* notas *字段的聲明是錯誤的。您的JavaBean不包含* getNotas()*公共方法。您可以查看[JavaBean數據源](http://jasperreports.sourceforge.net/sample.reference/datasource/index.html#javabeandatasources)示例以更好地瞭解如何使用* JavaBean數據源* –

+0

謝謝,那是我的問題。找到該字段並在報告的字段中添加該班的分班 –

回答

1

我損失了很多時間試圖弄清楚發生了什麼事,幾個小時我重複我是路過的數據源列表,並意識到我有沒有後投列表中正確類型。嘗試在將它發送到報告之前迭代列表。

相關問題