Getting Error retrieving field value from bean Exception with JasperReports API

Sachin Verma

I am trying to get a sample report generated by JasperReports but it is throwing some exception that I can not understand.

I have a bean:

class DataBean {

    public String country;
    public String name;

    public String getCountry() {
        return country;
    }

    public void setCountry(String country) {
        this.country = country;
    }

    public String getName() {
        return name;
    }

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

A class that results list of above bean:

class DataBeanList {
    public ArrayList<DataBean> getDataBeanList() {
        ArrayList<DataBean> dataBeanList = new ArrayList<DataBean>();
        dataBeanList.add(produce("Manisha", "India"));
        dataBeanList.add(produce("Dennis Ritchie", "USA"));
        dataBeanList.add(produce("V.Anand", "India"));
        dataBeanList.add(produce("Shrinath", "California"));
        return dataBeanList;
    }

    private DataBean produce(String name, String country) {
        DataBean dataBean = new DataBean();
        dataBean.setName(name);
        dataBean.setCountry(country);
        return dataBean;
    }
}

This is how i am doing:

public static void main(String[] args) throws Exception {
    String sourceFileName = "/home/oodles/Samples/jasper_report_template.jasper";
    DataBeanList DataBeanList = new DataBeanList();
    ArrayList<DataBean> dataList = DataBeanList.getDataBeanList();
    System.out.println("<<<" + dataList.get(0).getCountry());
    JasperReportBuilder report = DynamicReports.report();
    JRBeanCollectionDataSource beanColDataSource = new JRBeanCollectionDataSource(dataList, false);
    report.setDataSource(beanColDataSource);
    Map parameters = new HashMap();
    try {
        JasperFillManager.fillReportToFile(sourceFileName, parameters,
                beanColDataSource);
    } catch (JRException e) {
        e.printStackTrace();
    }
}

The Exception is the following:

    net.sf.jasperreports.engine.JRException: Error retrieving field value from bean : country
    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: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.fillToFile(JasperFillManager.java:542)
    at net.sf.jasperreports.engine.JasperFillManager.fillToFile(JasperFillManager.java:494)
    at net.sf.jasperreports.engine.JasperFillManager.fillReportToFile(JasperFillManager.java:874)
    at com.general.ReportsMain.main(ReportsMain.java:80)
Caused by: java.lang.NoSuchMethodException: Property 'country' has no getter method in class 'class com.general.DataBean'
    at org.apache.commons.beanutils.PropertyUtilsBean.getSimpleProperty(PropertyUtilsBean.java:1318)
    at org.apache.commons.beanutils.PropertyUtilsBean.getNestedProperty(PropertyUtilsBean.java:762)
    at org.apache.commons.beanutils.PropertyUtilsBean.getProperty(PropertyUtilsBean.java:837)
    at org.apache.commons.beanutils.PropertyUtils.getProperty(PropertyUtils.java:426)
    at net.sf.jasperreports.engine.data.JRAbstractBeanDataSource.getBeanProperty(JRAbstractBeanDataSource.java:111)
    ... 15 more

In case you need to see .jasper file source:
i am attaching only fields to show only meaningful code here:

<field name="country" class="java.lang.String">
    <fieldDescription><![CDATA[country]]></fieldDescription>
</field>
<field name="name" class="java.lang.String">
    <fieldDescription><![CDATA[name]]></fieldDescription>
</field>
Sachin Verma

Finally i figured out what you need to do to avoid any exception:

Your datasource is accessed in other packages to extract data from them and if the bean of your datasource is not public then it's not possible to access the class.
SO you need to make your class public (the bean class).

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Getting Error retrieving field value from bean Exception with JasperReports API

From Dev

net.sf.jasperreports.engine.JRException: Error retrieving field value from bean : First_name

From Dev

Error retrieving field value from bean

From Dev

JasperReport iReport: JRException: Error retrieving field value from bean

From Dev

JasperReport: JRException: Error retrieving field value from bean(Nested Bean Issue)

From Dev

Getting error while retrieving value from dropdown

From Dev

Retrieving value of JSF input field without managed bean property

From Dev

Retrieving value of JSF input field without managed bean property

From Dev

Getting value from API

From Dev

Error when retrieving value from Map

From Dev

Getting 'Cannot read property "length" from undefined' exception while rendering chart at JasperReports Server

From Dev

Getting exception while getting value of a field using reflection

From Dev

Json Parse Error when getting value from web api 2

From Dev

Getting error when try to fetch value from API response in Karate

From Dev

Retrieving the value from a Selenium Webdriver WebElement field and passing it to a java variable

From Dev

JasperReports: Getting JRRuntimeException: Error creating SAX parser

From Dev

Getting value from a function and put it in a input field

From Dev

Getting an XML value from a named field

From Dev

XPages Java Error: Error getting property 'dbName' from bean

From Dev

Retrieving the actual displayed link value from MediaWiki API

From Dev

Retrieving value from object

From Dev

Retrieving value from a method

From Dev

Retrieving value from database

From Dev

Retrieving data from API

From Dev

error retrieving distance and travel time values from a Google API ()

From Dev

getting value from radiobutton group that is binded to a managed bean

From Dev

Unable to retrieve value from a JavaBean while generating reports using JasperReports API

From Dev

Getting JSON Exception no value for?

From Dev

Getting JSON Exception no value for?

Related Related

  1. 1

    Getting Error retrieving field value from bean Exception with JasperReports API

  2. 2

    net.sf.jasperreports.engine.JRException: Error retrieving field value from bean : First_name

  3. 3

    Error retrieving field value from bean

  4. 4

    JasperReport iReport: JRException: Error retrieving field value from bean

  5. 5

    JasperReport: JRException: Error retrieving field value from bean(Nested Bean Issue)

  6. 6

    Getting error while retrieving value from dropdown

  7. 7

    Retrieving value of JSF input field without managed bean property

  8. 8

    Retrieving value of JSF input field without managed bean property

  9. 9

    Getting value from API

  10. 10

    Error when retrieving value from Map

  11. 11

    Getting 'Cannot read property "length" from undefined' exception while rendering chart at JasperReports Server

  12. 12

    Getting exception while getting value of a field using reflection

  13. 13

    Json Parse Error when getting value from web api 2

  14. 14

    Getting error when try to fetch value from API response in Karate

  15. 15

    Retrieving the value from a Selenium Webdriver WebElement field and passing it to a java variable

  16. 16

    JasperReports: Getting JRRuntimeException: Error creating SAX parser

  17. 17

    Getting value from a function and put it in a input field

  18. 18

    Getting an XML value from a named field

  19. 19

    XPages Java Error: Error getting property 'dbName' from bean

  20. 20

    Retrieving the actual displayed link value from MediaWiki API

  21. 21

    Retrieving value from object

  22. 22

    Retrieving value from a method

  23. 23

    Retrieving value from database

  24. 24

    Retrieving data from API

  25. 25

    error retrieving distance and travel time values from a Google API ()

  26. 26

    getting value from radiobutton group that is binded to a managed bean

  27. 27

    Unable to retrieve value from a JavaBean while generating reports using JasperReports API

  28. 28

    Getting JSON Exception no value for?

  29. 29

    Getting JSON Exception no value for?

HotTag

Archive