2

I'm following this tutorial: http://javabeansinjasper.blogspot.com/

I'm encountering difficulty when testing the java beans data source on iReport. I have packaged my app jar via mvn package and added it on iReport classpath.

My factory class looks like this:

public class JasperReportFactory {

    private static Vector proposalReports;

    public static void setProposalReports(ProposalReport report) {
        proposalReports = new Vector();
        proposalReports.add(report);
    }

    public static Collection getProposalReports() {
        return proposalReports;
    }
}

But I'm getting the following error:

enter image description here

The method don't return a valid Array or java.util.Collection!

Any ideas will be appreciated.!

Petter Friberg
  • 21,252
  • 9
  • 60
  • 109
lorraine batol
  • 6,001
  • 16
  • 55
  • 114

1 Answers1

1

Your JasperReportFactory.getProposalReports() is returning null

iReport calls JasperReportFactory.getProposalReports() but without first calling public static void setProposalReports(ProposalReport report)

Solution:

You need to make sure that that your private static Vector proposalReports; is not null (in fact in blog you provided they are creating the Vector in the getStudentList())

Example

public static Collection getProposalReports() {
    if (proposalReports==null){
        setProposalReports(new ProposalReport()) //mockup for iReport
    }
    return proposalReports;
}

While posting note that Vector is old java 1.4, you should consider to use List with type definition.

private static List<ProposalReport> proposalReports;

see Why is Java Vector class considered obsolete or deprecated?

Community
  • 1
  • 1
Petter Friberg
  • 21,252
  • 9
  • 60
  • 109
  • thank you for this, any ideas why the fields won't get populated on iReport even though the connection data source is now successful? I'm expecting I can now drag and drop fields but they are none. – lorraine batol Sep 25 '16 at 12:11
  • @yin03 If you don't get the fields automatically (retrive fields), create them manually (right click fields nodes, add field), give same name and class as in your bean. – Petter Friberg Sep 25 '16 at 12:16