2017-05-03 77 views
0

我收到了標題中提到的錯誤消息。我嘗試了在不同論壇中發現的所有內容,但都沒有成功。從bean中檢索字段值時出錯:JasperReports中的名稱

這是我Bean類:

public class NameBean { 
    private String reportName, shortDescription, description; 

    public NameBean(String reportName, String shortDescription, String description) { 
     this.reportName = reportName; 
     this.shortDescription = shortDescription; 
     this.description = description; 
    } 

    public String getName(){ 
     return reportName; 
    } 

    public String getShortDescription() { 
     return shortDescription; 
    } 

    public String getDescription() { 
     return description; 
    } 

    public void setName(String reportName){ 
     this.reportName = reportName; 
    } 

    public void setShortDescription(String shortDescription) { 
     this.shortDescription = shortDescription; 
    } 

    public void setDescription(String description) { 
     this.description = description; 
    } 
} 

這是工廠類:

public class TestFactory { 

    public static ArrayList generateCollection() { 
     ArrayList collection = new ArrayList(); 

     collection.add(new NameBean("PS_TF_VSGM-A-2535_01", "Automatisches Starten der Online-Prüfung und -Aktualisierung", 
       "Der Konfigurationsparameter zur Online-Prüfung und -Aktualisierung(MODE_ONLINE_CHECK) ist auf den Wert First konfiguriert. Es wird eine eGK in das Kartenterminal des Konnektorsimulators gesteckt für die im laufenden Quartalnoch keine Online-Prüfung durchgeführt wurde.")); 

     collection.add(new EntranceValuesBean("eingeschaltet", "online", "Ohne TLS", "Standard (PTV 1.6.0)", "Mandat > Terminal > Karte")); 

     return collection; 
    } 
} 

這是我的XML

<?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="test" pageWidth="595" pageHeight="842" columnWidth="535" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20" uuid="2f6e4db4-9f8f-4ffe-9759-6e1fd142f492"> 
    <property name="template.type" value="columnar"/> 
    <property name="com.jaspersoft.studio.data.defaultdataadapter" value="src/dataset1.xml"/> 
    <style name="Title" forecolor="#000000" fontName="Times New Roman" fontSize="50" isBold="false"/> 
    <style name="SubTitle" forecolor="#666666" fontName="Times New Roman" fontSize="18" isBold="false"/> 
    <style name="Column header" forecolor="#666666" fontName="Times New Roman" fontSize="14" isBold="true"/> 
    <style name="Detail" mode="Transparent" fontName="Times New Roman"/> 
    <style name="Row" mode="Transparent" fontName="Times New Roman" pdfFontName="Times-Roman"> 
     <conditionalStyle> 
      <conditionExpression><![CDATA[$V{REPORT_COUNT}%2 == 0]]></conditionExpression> 
      <style mode="Opaque" backcolor="#F0EFEF"/> 
     </conditionalStyle> 
    </style> 
    <field name="name" class="java.lang.String"> 
     <fieldDescription><![CDATA[name]]></fieldDescription> 
    </field> 
    <field name="description" class="java.lang.String"> 
     <fieldDescription><![CDATA[description]]></fieldDescription> 
    </field> 
    <field name="shortDescription" class="java.lang.String"> 
     <fieldDescription><![CDATA[shortDescription]]></fieldDescription> 
    </field> 
    <title> 
     <band height="290" splitType="Stretch"> 
      <staticText> 
       <reportElement style="Title" x="0" y="0" width="400" height="30" uuid="756c5f0f-cbe1-46b1-9f5a-645caa1a189e"/> 
       <textElement> 
        <font size="16" isBold="false"/> 
       </textElement> 
       <text><![CDATA[Konnektorsimmulator Testfall Protokoll: ]]></text> 
      </staticText> 
      <line> 
       <reportElement positionType="FixRelativeToBottom" x="-20" y="80" width="551" height="1" uuid="5e41185f-9c90-45ca-839b-e28b308c1430"/> 
      </line> 
     </band> 
    </title> 
    <detail> 
     <band height="91" splitType="Stretch"/> 
    </detail> 
</jasperReport> 

這是我得到的錯誤:

net.sf.jasperreports.engine.JRException: net.sf.jasperreports.engine.JRException: Error retrieving field value from bean: name. 
    at com.jaspersoft.studio.editor.preview.view.control.ReportControler.fillReport(ReportControler.java:537) 
    at com.jaspersoft.studio.editor.preview.view.control.ReportControler.access$20(ReportControler.java:512) 
    at com.jaspersoft.studio.editor.preview.view.control.ReportControler$5.run(ReportControler.java:393) 
    at org.eclipse.core.internal.jobs.Worker.run(Worker.java:55) 
Caused by: net.sf.jasperreports.engine.JRException: Error retrieving field value from bean: name. 
    at net.sf.jasperreports.engine.data.JRAbstractBeanDataSource.getBeanProperty(JRAbstractBeanDataSource.java:134) 
    at net.sf.jasperreports.engine.data.JRAbstractBeanDataSource.getFieldValue(JRAbstractBeanDataSource.java:99) 
    at net.sf.jasperreports.engine.data.JRBeanCollectionDataSource.getFieldValue(JRBeanCollectionDataSource.java:104) 
    at net.sf.jasperreports.engine.fill.JRFillDataset.setOldValues(JRFillDataset.java:1373) 
    at net.sf.jasperreports.engine.fill.JRFillDataset.next(JRFillDataset.java:1274) 
    at net.sf.jasperreports.engine.fill.JRFillDataset.next(JRFillDataset.java:1250) 
    at net.sf.jasperreports.engine.fill.JRBaseFiller.next(JRBaseFiller.java:1056) 
    at net.sf.jasperreports.engine.fill.JRVerticalFiller.fillReport(JRVerticalFiller.java:117) 
    at net.sf.jasperreports.engine.fill.JRBaseFiller.fill(JRBaseFiller.java:580) 
    at net.sf.jasperreports.engine.fill.BaseFillHandle$ReportFill.run(BaseFillHandle.java:123) 
    at java.lang.Thread.run(Thread.java:745) 
Caused by: java.lang.NoSuchMethodException: Unknown property 'name' on class 'class EntranceValuesBean' 
    at org.apache.commons.beanutils.PropertyUtilsBean.getSimpleProperty(PropertyUtilsBean.java:1277) 
    at org.apache.commons.beanutils.PropertyUtilsBean.getNestedProperty(PropertyUtilsBean.java:808) 
    at org.apache.commons.beanutils.PropertyUtilsBean.getProperty(PropertyUtilsBean.java:884) 
    at org.apache.commons.beanutils.PropertyUtils.getProperty(PropertyUtils.java:464) 
    at net.sf.jasperreports.engine.data.JRAbstractBeanDataSource.getBeanProperty(JRAbstractBeanDataSource.java:114) 
    ... 10 more 

我絕對不知道如何解決這個問題。

+0

什麼是'EntranceValuesBean'?你是怎麼用這門課的?您應該將傳遞數據源的代碼發佈到報表中 –

回答

0

從堆棧跟蹤

Caused by: java.lang.NoSuchMethodException: Unknown property 'name' on class 'class EntranceValuesBean' 
    at org.apache.commons.beanutils.PropertyUtilsBean.getSimpleProperty(PropertyUtilsBean.java:1277) 
    at org.apache.commons.beanutils.PropertyUtilsBean.getNestedProperty(PropertyUtilsBean.java:808) 
    at org.apache.commons.beanutils.PropertyUtilsBean.getProperty(PropertyUtilsBean.java:884) 
    at org.apache.commons.beanutils.PropertyUtils.getProperty(PropertyUtils.java:464) 
    at net.sf.jasperreports.engine.data.JRAbstractBeanDataSource.getBeanProperty(JRAbstractBeanDataSource.java:114) 

看來這個問題是由於該類EntranceValuesBean。 檢查該類是否有名爲getName的getter方法。

0

感謝您提供EntranceValuesBean類的建議。我刪除它並將代碼寫入NameBean類中。它正在工作。

相關問題