JasperReports - net.sf.jasperreports.engine.JRException:从bean中检索字段值时出错

时间:2014-08-07 13:03:33

标签: java jasper-reports

我一直被困在这上面,这让我疯了。我真的需要一些帮助:(。

我尝试使用JasperReports生成报告,但是当报告填满时我收到此错误。

    net.sf.jasperreports.engine.JRException: Error retrieving field value from bean : relatedID 
    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:1554)
    at net.sf.jasperreports.engine.fill.JRVerticalFiller.fillReport(JRVerticalFiller.java:149)
    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 com.isyc.oncustomer.reports.jasper.JasperReportGenerator.buildReport(JasperReportGenerator.java:155)
    at com.isyc.oncustomer.scheduler.ReportJob.execute(ReportJob.java:50)
    at org.quartz.core.JobRunShell.run(JobRunShell.java:213)
    at org.quartz.simpl.SimpleThreadPool$WorkerThread.run(SimpleThreadPool.java:557)
Caused by: java.lang.NoSuchMethodException: Unknown property 'relatedID ' on class 'class com.isyc.oncustomer.reports.jasper.SmsSendReport'
    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)
    ... 17 more

这是我用于数据源的bean:SmsSendReport.java

public class SmsSendReport {

    private Long interactionID = 0L;
    private String relatedObjectType = "";
    private Long relatedID = 0L;
    private Long smsID = 0L;
    private String smsReceiver = "";
    private String smsMessage;
    private String smsRelatedObject = "";
    private Date smsSendDate;
    private Boolean smsStatus;

    public Long getInteractionID() {
        return interactionID;
    }
    public void setInteractionID(Long interactionID) {
        this.interactionID = interactionID;
    }
    public String getRelatedObjectType() {
        return relatedObjectType;
    }
    public void setRelatedObjectType(String relatedObjectType) {
        this.relatedObjectType = relatedObjectType;
    }
    public Long getRelatedID() {
        return relatedID;
    }
    public void setRelatedID(Long relatedID) {
        this.relatedID = relatedID;
    }
    public Long getSmsID() {
        return smsID;
    }
    public void setSmsID(Long smsID) {
        this.smsID = smsID;
    }
    public String getSmsReceiver() {
        return smsReceiver;
    }
    public void setSmsReceiver(String smsReceiver) {
        this.smsReceiver = smsReceiver;
    }
    public String getSmsRelatedObject() {
        return smsRelatedObject;
    }
    public void setSmsRelatedObject(String smsRelatedObject) {
        this.smsRelatedObject = smsRelatedObject;
    }
    public Date getSmsSendDate() {
        return smsSendDate;
    }
    public void setSmsSendDate(Date smsSendDate) {
        this.smsSendDate = smsSendDate;
    }
    public Boolean getSmsStatus() {
        return smsStatus;
    }
    public void setSmsStatus(Boolean smsStatus) {
        this.smsStatus = smsStatus;
    }
    public String getSmsMessage() {
        return smsMessage;
    }
    public void setSmsMessage(String smsMessage) {
        this.smsMessage = smsMessage;
    }

}

这是.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="smsSendReport" language="groovy" pageWidth="850" pageHeight="756" whenNoDataType="AllSectionsNoDetail" columnWidth="850" leftMargin="0" rightMargin="0" topMargin="0" bottomMargin="0" isIgnorePagination="true" uuid="3d66dd41-27ea-4c0d-ab2e-e2074e6f740e">
    <property name="ireport.zoom" value="1.3310000000000013"/>
    <property name="ireport.x" value="0"/>
    <property name="ireport.y" value="0"/>
    <parameter name="image_path" class="java.lang.String"/>
    <parameter name="MONTH" class="java.lang.Integer"/>
    <parameter name="YEAR" class="java.lang.String"/>
    <parameter name="REPORT_DIR" class="java.lang.String" isForPrompting="false">
        <defaultValueExpression><![CDATA["/home/jroy/weblogicworkspace/reports/"]]></defaultValueExpression>
    </parameter>
    <queryString>
        <![CDATA[]]>
    </queryString>
    <field name="interactionID" class="java.lang.Long"/>
    <field name="relatedID " class="java.lang.Long"/>
    <field name="SmsID" class="java.lang.Long"/>
    <field name="relatedObjectType" class="java.lang.String"/>
    <field name="smsRelatedObject " class="java.lang.String"/>
    <field name="smsReceiver" class="java.lang.String"/>
    <field name="smsSendDate" class="java.sql.Timestamp"/>
    <field name="smsSended" class="java.lang.Boolean"/>
    <variable name="datasource" class="net.sf.jasperreports.engine.JRDataSource" resetType="None">
        <variableExpression><![CDATA[$P{REPORT_DATA_SOURCE}.cloneDataSource()]]></variableExpression>
        <initialValueExpression><![CDATA[$P{REPORT_DATA_SOURCE}.cloneDataSource()]]></initialValueExpression>
    </variable>
    <columnHeader>
        <band height="49" splitType="Stretch">
            <staticText>
                <reportElement uuid="3259d1dc-610f-4f10-9dde-1f50038a3cb7" mode="Opaque" x="62" y="0" width="100" height="49" forecolor="#FFFFFF" backcolor="#0070C0"/>
                <box rightPadding="0">
                    <topPen lineWidth="0.75" lineColor="#000000"/>
                    <leftPen lineWidth="0.75" lineColor="#000000"/>
                    <bottomPen lineWidth="0.75" lineColor="#000000"/>
                    <rightPen lineWidth="0.75" lineColor="#000000"/>
                </box>
                <textElement textAlignment="Center" verticalAlignment="Middle" rotation="None" markup="none">
                    <font fontName="SansSerif" size="10" isBold="true" isItalic="false" isUnderline="false" isStrikeThrough="false" pdfEncoding="Cp1252" isPdfEmbedded="false"/>
                    <paragraph lineSpacing="Single"/>
                </textElement>
                <text><![CDATA[Tipo de objeto]]></text>
            </staticText>
            <staticText>
                <reportElement uuid="09202e40-bc33-4330-b2cc-e3b416339a86" mode="Opaque" x="0" y="0" width="62" height="49" forecolor="#FFFFFF" backcolor="#0070C0"/>
                <box rightPadding="0">
                    <topPen lineWidth="0.75" lineColor="#000000"/>
                    <leftPen lineWidth="0.75" lineColor="#000000"/>
                    <bottomPen lineWidth="0.75" lineColor="#000000"/>
                    <rightPen lineWidth="0.75" lineColor="#000000"/>
                </box>
                <textElement textAlignment="Center" verticalAlignment="Middle" rotation="None" markup="none">
                    <font fontName="SansSerif" size="10" isBold="true" isItalic="false" isUnderline="false" isStrikeThrough="false" pdfEncoding="Cp1252" isPdfEmbedded="false"/>
                    <paragraph lineSpacing="Single"/>
                </textElement>
                <text><![CDATA[Interacción ID]]></text>
            </staticText>
            <staticText>
                <reportElement uuid="a7eb4a41-93ce-4b6a-a3bd-c7326b6e8976" mode="Opaque" x="162" y="0" width="91" height="49" forecolor="#FFFFFF" backcolor="#0070C0"/>
                <box rightPadding="0">
                    <topPen lineWidth="0.75" lineColor="#000000"/>
                    <leftPen lineWidth="0.75" lineColor="#000000"/>
                    <bottomPen lineWidth="0.75" lineColor="#000000"/>
                    <rightPen lineWidth="0.75" lineColor="#000000"/>
                </box>
                <textElement textAlignment="Center" verticalAlignment="Middle" rotation="None" markup="none">
                    <font fontName="SansSerif" size="10" isBold="true" isItalic="false" isUnderline="false" isStrikeThrough="false" pdfEncoding="Cp1252" isPdfEmbedded="false"/>
                    <paragraph lineSpacing="Single"/>
                </textElement>
                <text><![CDATA[ID del objeto]]></text>
            </staticText>
            <staticText>
                <reportElement uuid="2756cf32-b642-4a78-80fb-b6b96056db47" mode="Opaque" x="253" y="0" width="62" height="49" forecolor="#FFFFFF" backcolor="#0070C0"/>
                <box rightPadding="0">
                    <topPen lineWidth="0.75" lineColor="#000000"/>
                    <leftPen lineWidth="0.75" lineColor="#000000"/>
                    <bottomPen lineWidth="0.75" lineColor="#000000"/>
                    <rightPen lineWidth="0.75" lineColor="#000000"/>
                </box>
                <textElement textAlignment="Center" verticalAlignment="Middle" rotation="None" markup="none">
                    <font fontName="SansSerif" size="10" isBold="true" isItalic="false" isUnderline="false" isStrikeThrough="false" pdfEncoding="Cp1252" isPdfEmbedded="false"/>
                    <paragraph lineSpacing="Single"/>
                </textElement>
                <text><![CDATA[ID]]></text>
            </staticText>
            <staticText>
                <reportElement uuid="511609ab-069e-4e38-add7-e68691166247" mode="Opaque" x="526" y="0" width="94" height="49" forecolor="#FFFFFF" backcolor="#0070C0"/>
                <box rightPadding="0">
                    <topPen lineWidth="0.75" lineColor="#000000"/>
                    <leftPen lineWidth="0.75" lineColor="#000000"/>
                    <bottomPen lineWidth="0.75" lineColor="#000000"/>
                    <rightPen lineWidth="0.75" lineColor="#000000"/>
                </box>
                <textElement textAlignment="Center" verticalAlignment="Middle" rotation="None" markup="none">
                    <font fontName="SansSerif" size="10" isBold="true" isItalic="false" isUnderline="false" isStrikeThrough="false" pdfEncoding="Cp1252" isPdfEmbedded="false"/>
                    <paragraph lineSpacing="Single"/>
                </textElement>
                <text><![CDATA[Teléfono]]></text>
            </staticText>
            <staticText>
                <reportElement uuid="cbc60aa4-da54-49a8-b0cd-cc8728389abf" mode="Opaque" x="620" y="0" width="101" height="49" forecolor="#FFFFFF" backcolor="#0070C0"/>
                <box rightPadding="0">
                    <topPen lineWidth="0.75" lineColor="#000000"/>
                    <leftPen lineWidth="0.75" lineColor="#000000"/>
                    <bottomPen lineWidth="0.75" lineColor="#000000"/>
                    <rightPen lineWidth="0.75" lineColor="#000000"/>
                </box>
                <textElement textAlignment="Center" verticalAlignment="Middle" rotation="None" markup="none">
                    <font fontName="SansSerif" size="10" isBold="true" isItalic="false" isUnderline="false" isStrikeThrough="false" pdfEncoding="Cp1252" isPdfEmbedded="false"/>
                    <paragraph lineSpacing="Single"/>
                </textElement>
                <text><![CDATA[Fecha de envío]]></text>
            </staticText>
            <staticText>
                <reportElement uuid="cbc60aa4-da54-49a8-b0cd-cc8728389abf" mode="Opaque" x="721" y="0" width="200" height="49" forecolor="#FFFFFF" backcolor="#0070C0"/>
                <box rightPadding="0">
                    <topPen lineWidth="0.75" lineColor="#000000"/>
                    <leftPen lineWidth="0.75" lineColor="#000000"/>
                    <bottomPen lineWidth="0.75" lineColor="#000000"/>
                    <rightPen lineWidth="0.75" lineColor="#000000"/>
                </box>
                <textElement textAlignment="Center" verticalAlignment="Middle" rotation="None" markup="none">
                    <font fontName="SansSerif" size="10" isBold="true" isItalic="false" isUnderline="false" isStrikeThrough="false" pdfEncoding="Cp1252" isPdfEmbedded="false"/>
                    <paragraph lineSpacing="Single"/>
                </textElement>
                <text><![CDATA[Estado]]></text>
            </staticText>
            <staticText>
                <reportElement uuid="511609ab-069e-4e38-add7-e68691166247" mode="Opaque" x="315" y="0" width="211" height="49" forecolor="#FFFFFF" backcolor="#0070C0"/>
                <box rightPadding="0">
                    <topPen lineWidth="0.75" lineColor="#000000"/>
                    <leftPen lineWidth="0.75" lineColor="#000000"/>
                    <bottomPen lineWidth="0.75" lineColor="#000000"/>
                    <rightPen lineWidth="0.75" lineColor="#000000"/>
                </box>
                <textElement textAlignment="Center" verticalAlignment="Middle" rotation="None" markup="none">
                    <font fontName="SansSerif" size="10" isBold="true" isItalic="false" isUnderline="false" isStrikeThrough="false" pdfEncoding="Cp1252" isPdfEmbedded="false"/>
                    <paragraph lineSpacing="Single"/>
                </textElement>
                <text><![CDATA[Destinatario SMS]]></text>
            </staticText>
        </band>
    </columnHeader>
    <detail>
        <band height="15" splitType="Stretch">
            <textField isStretchWithOverflow="true" pattern="#,##0.00" isBlankWhenNull="true">
                <reportElement uuid="421ab086-3723-438b-9021-1a2f6da5002a" stretchType="RelativeToTallestObject" x="62" y="0" width="100" height="15"/>
                <box leftPadding="5">
                    <topPen lineWidth="0.5"/>
                    <leftPen lineWidth="0.5"/>
                    <bottomPen lineWidth="0.5"/>
                    <rightPen lineWidth="0.5"/>
                </box>
                <textElement verticalAlignment="Middle">
                    <font fontName="Arial" size="8"/>
                    <paragraph leftIndent="5"/>
                </textElement>
                <textFieldExpression><![CDATA[$F{relatedObjectType}]]></textFieldExpression>
            </textField>
            <textField isStretchWithOverflow="true" isBlankWhenNull="true">
                <reportElement uuid="c0e0ce09-e527-49d5-a777-72d82b8d920b" stretchType="RelativeToTallestObject" mode="Opaque" x="162" y="0" width="91" height="15" forecolor="#000000" backcolor="#FFFFFF"/>
                <box>
                    <pen lineWidth="0.5" lineStyle="Solid" lineColor="#000000"/>
                    <topPen lineWidth="0.5" lineStyle="Solid" lineColor="#000000"/>
                    <leftPen lineWidth="0.5" lineStyle="Solid" lineColor="#000000"/>
                    <bottomPen lineWidth="0.5" lineStyle="Solid" lineColor="#000000"/>
                    <rightPen lineWidth="0.5" lineStyle="Solid" lineColor="#000000"/>
                </box>
                <textElement verticalAlignment="Middle">
                    <font fontName="Arial" size="8"/>
                    <paragraph leftIndent="5"/>
                </textElement>
                <textFieldExpression><![CDATA[$F{relatedID }]]></textFieldExpression>
            </textField>
            <textField isStretchWithOverflow="true" isBlankWhenNull="true">
                <reportElement uuid="48b46bd4-f67c-4ac9-8fa7-139328b8f95d" stretchType="RelativeToTallestObject" mode="Opaque" x="253" y="0" width="62" height="15" forecolor="#000000" backcolor="#FFFFFF"/>
                <box>
                    <pen lineWidth="0.5" lineStyle="Solid" lineColor="#000000"/>
                    <topPen lineWidth="0.5" lineStyle="Solid" lineColor="#000000"/>
                    <leftPen lineWidth="0.5" lineStyle="Solid" lineColor="#000000"/>
                    <bottomPen lineWidth="0.5" lineStyle="Solid" lineColor="#000000"/>
                    <rightPen lineWidth="0.5" lineStyle="Solid" lineColor="#000000"/>
                </box>
                <textElement verticalAlignment="Middle">
                    <font fontName="Arial" size="8"/>
                    <paragraph leftIndent="5"/>
                </textElement>
                <textFieldExpression><![CDATA[$F{SmsID}]]></textFieldExpression>
            </textField>
            <textField isStretchWithOverflow="true" isBlankWhenNull="true">
                <reportElement uuid="ee04dee8-2ef7-4d79-b8a4-f3f5e19f9411" stretchType="RelativeToTallestObject" mode="Opaque" x="526" y="0" width="94" height="15" forecolor="#000000" backcolor="#FFFFFF"/>
                <box>
                    <pen lineWidth="0.5" lineStyle="Solid" lineColor="#000000"/>
                    <topPen lineWidth="0.5" lineStyle="Solid" lineColor="#000000"/>
                    <leftPen lineWidth="0.5" lineStyle="Solid" lineColor="#000000"/>
                    <bottomPen lineWidth="0.5" lineStyle="Solid" lineColor="#000000"/>
                    <rightPen lineWidth="0.5" lineStyle="Solid" lineColor="#000000"/>
                </box>
                <textElement verticalAlignment="Middle">
                    <font fontName="Arial" size="8"/>
                    <paragraph leftIndent="5"/>
                </textElement>
                <textFieldExpression><![CDATA[$F{smsReceiver}]]></textFieldExpression>
            </textField>
            <textField isStretchWithOverflow="true" pattern="dd/MM/yyyy HH.mm.ss" isBlankWhenNull="true">
                <reportElement uuid="875b5eba-a754-4535-91f1-c3e0ece9a456" stretchType="RelativeToTallestObject" mode="Opaque" x="620" y="0" width="101" height="15" forecolor="#000000" backcolor="#FFFFFF"/>
                <box>
                    <pen lineWidth="0.5" lineStyle="Solid" lineColor="#000000"/>
                    <topPen lineWidth="0.5" lineStyle="Solid" lineColor="#000000"/>
                    <leftPen lineWidth="0.5" lineStyle="Solid" lineColor="#000000"/>
                    <bottomPen lineWidth="0.5" lineStyle="Solid" lineColor="#000000"/>
                    <rightPen lineWidth="0.5" lineStyle="Solid" lineColor="#000000"/>
                </box>
                <textElement verticalAlignment="Middle">
                    <font fontName="Arial" size="8"/>
                    <paragraph leftIndent="5"/>
                </textElement>
                <textFieldExpression><![CDATA[$F{smsSendDate}]]></textFieldExpression>
            </textField>
            <textField isStretchWithOverflow="true" pattern="" isBlankWhenNull="true">
                <reportElement uuid="875b5eba-a754-4535-91f1-c3e0ece9a456" stretchType="RelativeToTallestObject" mode="Opaque" x="721" y="0" width="200" height="15" forecolor="#000000" backcolor="#FFFFFF"/>
                <box>
                    <pen lineWidth="0.5" lineStyle="Solid" lineColor="#000000"/>
                    <topPen lineWidth="0.5" lineStyle="Solid" lineColor="#000000"/>
                    <leftPen lineWidth="0.5" lineStyle="Solid" lineColor="#000000"/>
                    <bottomPen lineWidth="0.5" lineStyle="Solid" lineColor="#000000"/>
                    <rightPen lineWidth="0.5" lineStyle="Solid" lineColor="#000000"/>
                </box>
                <textElement verticalAlignment="Middle">
                    <font fontName="Arial" size="8"/>
                    <paragraph leftIndent="5"/>
                </textElement>
                <textFieldExpression><![CDATA[$F{smsSended}]]></textFieldExpression>
            </textField>
            <textField isStretchWithOverflow="true" isBlankWhenNull="true">
                <reportElement uuid="ee04dee8-2ef7-4d79-b8a4-f3f5e19f9411" stretchType="RelativeToTallestObject" mode="Opaque" x="315" y="0" width="211" height="15" forecolor="#000000" backcolor="#FFFFFF"/>
                <box>
                    <pen lineWidth="0.5" lineStyle="Solid" lineColor="#000000"/>
                    <topPen lineWidth="0.5" lineStyle="Solid" lineColor="#000000"/>
                    <leftPen lineWidth="0.5" lineStyle="Solid" lineColor="#000000"/>
                    <bottomPen lineWidth="0.5" lineStyle="Solid" lineColor="#000000"/>
                    <rightPen lineWidth="0.5" lineStyle="Solid" lineColor="#000000"/>
                </box>
                <textElement verticalAlignment="Middle">
                    <font fontName="Arial" size="8"/>
                    <paragraph leftIndent="5"/>
                </textElement>
                <textFieldExpression><![CDATA[$F{smsRelatedObject }]]></textFieldExpression>
            </textField>
            <textField isStretchWithOverflow="true" pattern="#,##0.00" isBlankWhenNull="true">
                <reportElement uuid="421ab086-3723-438b-9021-1a2f6da5002a" stretchType="RelativeToTallestObject" x="0" y="0" width="62" height="15"/>
                <box leftPadding="5">
                    <topPen lineWidth="0.5"/>
                    <leftPen lineWidth="0.5"/>
                    <bottomPen lineWidth="0.5"/>
                    <rightPen lineWidth="0.5"/>
                </box>
                <textElement verticalAlignment="Middle">
                    <font fontName="Arial" size="8"/>
                    <paragraph leftIndent="5"/>
                </textElement>
                <textFieldExpression><![CDATA[$F{interactionID}]]></textFieldExpression>
            </textField>
        </band>
    </detail>
</jasperReport>

正确生成SmsSendReport对象的集合。我无法理解为什么我会收到此错误。 谢谢!

1 个答案:

答案 0 :(得分:0)

1。)检查jasper报告中的字段名称msg。 2.)确保字段名称在bean类中   private String msg;

public String getmsg()
{
    return msg;
}
public void setmsg(String msg) {
    this.msg = msg;

}

3。)最后返回名称应该得到,你提到的字段名称是什么......