执行从 JAVA 传递的 Jasper (Ireport) 时出现异常

Getting exception while executing Jasper (Ireport) passing from JAVA

异常抛出,无法从 bean 中识别字段名称,

JRXML 文件使用 Jaspersoft Studio 版本 6.2.2 创建

    <queryString>
        <![CDATA[]]>
    </queryString>
    <field name="barcodeNo" class="java.lang.String">
        <fieldDescription><![CDATA[]]></fieldDescription>
    </field>
    <background>
        <band splitType="Stretch"/>
    </background>
    <detail>
        <band height="28" splitType="Stretch">
            <componentElement>
                <reportElement x="0" y="11" width="85" height="17" uuid="dd489dd8-2c98-4aa0-9424-8f657197b22c"/>
                <jr:barbecue xmlns:jr="http://jasperreports.sourceforge.net/jasperreports/components" xsi:schemaLocation="http://jasperreports.sourceforge.net/jasperreports/components http://jasperreports.sourceforge.net/xsd/components.xsd" type="Code128" drawText="true" checksumRequired="false">
                    <jr:codeExpression><![CDATA[$F{barcodeNo}]]></jr:codeExpression>
                </jr:barbecue>
            </componentElement>
            <textField>
                <reportElement x="20" y="1" width="30" height="9" uuid="071ed7be-b4b9-4e60-8aea-0c9bb6cd55fe"/>
                <textElement>
                    <font size="4"/>
                </textElement>
                <textFieldExpression><![CDATA[$F{barcodeNo}]]></textFieldExpression>
            </textField>
        </band>
    </detail>
</jasperReport>

来自 java 服务

        List<String> barcodeList = getBarcodesFromRange(startBarcode, endBarcode);
        Map<String, Object> parametersMap = new HashMap<>();
        JasperReport jasperReport = JasperCompileManager.compileReport(resource.getInputStream());
        JasperPrint jasperPrint = JasperFillManager.fillReport(jasperReport, parametersMap, getDataSource());

        return jasperPrint;
    }


private static JRDataSource getDataSource() {
        Collection<BarcodePrint> coll = new ArrayList<>();
        coll.add(new BarcodePrint("1234","3333"));
        coll.add(new BarcodePrint("1111","3333"));

        return new JRBeanCollectionDataSource(coll);
    

填充数据的 Bean

public class BarcodePrint{
String barcodeNo;
String desc;

    public BarcodePrint(String barcodeNo, String desc) {
        this.barcodeNo = barcodeNo;
        this.desc = desc;
    }

    public String getBarcodeNo() {
        return barcodeNo;
    }

    public void setBarcodeNo(String barcodeNo) {
        this.barcodeNo = barcodeNo;
    }

    public String getDesc() {
        return desc;
    }

    public void setDesc(String desc) {
        this.desc = desc;
    }
}

获取异常,

原因:java.lang.NoSuchMethodException:class 'class com.int99.pos9.domain.BarcodePrint'

上未知 属性 ''

只需更改以下代码行,对我来说就成功了

` return new JRBeanCollectionDataSource(coll,false);`