Jump to content
We've recently updated our Privacy Statement, available here ×

JRDataSource: Class does not return a datasource object


pawel.silberring

Recommended Posts

I am new with JasperStudio 6.0.3. I am trying to implement a custom JRDataSource. I have created a class:
public class JRTJasperReportTotals implements JRDataSource

This class implements the next() and the getFieldValue() methods and contains a method:
    public static JRDataSource getDataSource()
    {
        return new JRTJasperReportTotals();
    }

The Class is then packed into a .jar

When I create a new Data Adapter, this is how the Wizard looks like:
converted-file.png.0bd037fb84bdd7fd021174fdbdaa5034.png

Pressing Test gives me:

converted-file.png.ac81f2a1491f2eb6478b1868e75623bb.png

 

What am I doing wrong here? Thank you in advance for any hint!

Link to comment
Share on other sites

  • 4 months later...
  • Replies 6
  • Created
  • Last Reply

Top Posters In This Topic

Hi Pawel, did you find a solution yet? I'm ahving exactly the same problem with Jaspersoft Studio, while iReport is accepting it most of the time. Pls contact me or post an answer here if you solved it! Thx a lot :)

Link to comment
Share on other sites

I had to create the complete data source code within the Jaspersoft Studio environment.

I use the Reporter in a larger project. so I wanted to integrate it into the environment of the project, but that turned out to be difficult.

What I do now is a minimal interface within Jaspersoft and from there, I use objects, which were created in my project. Here is my code:

import pJasperReport.JRTJasperReportTotals;    // This is the link object to my project
import net.sf.jasperreports.engine.JRDataSource;
import net.sf.jasperreports.engine.JRException;
import net.sf.jasperreports.engine.JRField;

public class TotalsTable implements JRDataSource {

    JRTJasperReportTotals JRTaJRTJasperReportTotals = null;
    String sTrace = "Init";
    
    /**************************************************************/
    public Object getFieldValue(JRField arg0) throws JRException {
        // TODO Auto-generated method stub
        String sResult = JRTaJRTJasperReportTotals.JRTGetField(arg0.getName());
        return sResult;
    }

    /**************************************************************/
    public boolean next() throws JRException {
        boolean bResult = false;
        
        if (JRTaJRTJasperReportTotals == null)
        {
            JRTaJRTJasperReportTotals = new JRTJasperReportTotals();
            sTrace = JRTaJRTJasperReportTotals.JRTLoadTotals();
        }
        bResult = JRTaJRTJasperReportTotals.JRTNext();
        return bResult;
    }

    /**************************************************************/
    public static JRDataSource getDataSource()
    {
        return new TotalsTable();
    }

}
 

I hope, this helps you a step forward.

Link to comment
Share on other sites

I might understand what you did. I have a JRDataSource with Provider and import the whole built jar then to my project via a data adapter. That produces the known ClassCastExecption, idk why though. I will try to access my DataSource with a minimal Connector written in the Studio or try out some stuff these days. I think i will respond again if i have representative results from that :)

Thx a lot for your quick answer, it's a step toward the solution, in the end maybe the only one out there i found.

Link to comment
Share on other sites

Hi,

the code above is some sort of a minimal interface, written within the environment of JasperReport. The object JRTaJRTJasperReportTotals is a class within my project and my minimal interface calls methods of this class with the same parameters and purpose. This allows me to program the more complex parts within my usual environment.

To make sure, this class is available for JasperReport, I create a .jar, which contains the object and put it into the directory of the Jasperreport files. Then I can start creation of the report:

        JasperPrint aJasperPrint = null;
        Exporter<ExporterInput, PdfReportConfiguration, PdfExporterConfiguration, OutputStreamExporterOutput> aExporter = null;

                 aJasperPrint = JasperFillManager.fillReport(sJasperReportFileName, aHashMap, new net.sf.jasperreports.engine.JREmptyDataSource() );
                aExporter = new net.sf.jasperreports.engine.export.JRPdfExporter();
                aExporter.setExporterInput(new SimpleExporterInput(aJasperPrint));
                aExporter.setExporterOutput(new SimpleOutputStreamExporterOutput(SRPsReportFileName));
                aExporter.exportReport();

aHashmap is a map containing the parameters of my report.

Hope, that helps you a step forward!
 

 

Link to comment
Share on other sites

  • 4 years later...

I'm running with the current latest version of the Eclipse plugin (6.15?) for community edition in Eclipse v 2019-09
I was running into a problem where I was creating duplicating the sample on https://community.jaspersoft.com/wiki/how-create-and-use-jrdatasource-adapter (how to create and use a jrdatasource adapater), but it would fail the test. Outside of removing the comments and the different project path (building it where I needed it to integrate), it was a verbatim copy-paste proof-of-concept.

I would always receive a "method does not return a 'JRDataSource' object" error every time I would test the adapter.
I tried creating a quick sample project and duplicated only the needed files over (data source, POM, etc) and it worked.

The solution that I came across was my Eclipse project setup was not completely standard. In an effort to minimize "cross contamination" between IDE and code, I was running my setup through multiple folder locations (code in a "codespace" folder and IDE in a "workspace" folder).
It appears that the program expects the Eclipse configurations to be in the same root folder as the code. When I moved the Eclipse configurations over to the same root folder (matching the quick sample) the tester passed without any errors.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×
×
  • Create New...