Jump to content
Changes to the Jaspersoft community edition download ×

How to solve this error?


Recommended Posts

I am trying fill the parameters of my table in the report with the data from a JavaBean with this code:

package report;/* * To change this license header, choose License Headers in Project Properties. * To change this template file, choose Tools | Templates * and open the template in the editor. */import java.io.File;import java.io.FileNotFoundException;import java.io.FileOutputStream;import java.io.InputStream;import java.io.OutputStream;import java.util.ArrayList;import java.util.HashMap;import java.util.List;import java.util.Map;import net.sf.jasperreports.engine.JREmptyDataSource;import net.sf.jasperreports.engine.JRException;import net.sf.jasperreports.engine.JasperCompileManager;import net.sf.jasperreports.engine.JasperExportManager;import net.sf.jasperreports.engine.JasperFillManager;import net.sf.jasperreports.engine.JasperPrint;import net.sf.jasperreports.engine.JasperReport;import net.sf.jasperreports.engine.data.JRBeanCollectionDataSource;/** * * @author doglas */public class JasperTableExample {    public static void main(String[] args) {        try {            /* User home directory location */            String userHomeDirectory = System.getProperty("user.home");            /* Output file location */            String outputFile = userHomeDirectory + File.separatorChar + "JasperTableExample.pdf";            /* List to hold Items */            List<Item> listItems = new ArrayList<Item>();            /* Create Items */            Item iPhone = new Item();            iPhone.setName("iPhone 6S");            iPhone.setPrice(65000.00);            Item iPad = new Item();            iPad.setName("iPad Pro");            iPad.setPrice(70000.00);            /* Add Items to List */            listItems.add(iPhone);            listItems.add(iPad);            /* Convert List to JRBeanCollectionDataSource */            JRBeanCollectionDataSource itemsJRBean = new JRBeanCollectionDataSource(listItems);            /* Map to hold Jasper report Parameters */            Map<String, Object> parameters = new HashMap<String, Object>();            parameters.put("ItemDataSource", itemsJRBean);            /* Using compiled version(.jasper) of Jasper report to generate PDF */            InputStream fonte = JasperTableExample.class.getResourceAsStream("template_Table.jrxml");            JasperReport report = JasperCompileManager.compileReport(fonte);            JasperPrint jasperPrint = JasperFillManager.fillReport(report, parameters, new JREmptyDataSource());            /* outputStream to create PDF */            OutputStream outputStream = new FileOutputStream(new File(outputFile));            /* Write content to PDF file */            JasperExportManager.exportReportToPdfStream(jasperPrint, outputStream);            System.out.println("File Generated");        } catch (JRException ex) {            ex.printStackTrace();        } catch (FileNotFoundException ex) {            ex.printStackTrace();        }    }}[/code]

But when I try call the report the java returns this error:

Exception in thread "main" java.lang.NoSuchMethodError: org.slf4j.spi.LocationAwareLogger.log(Lorg/slf4j/Marker;Ljava/lang/String;ILjava/lang/String;[Ljava/lang/Object;Ljava/lang/Throwable;)V
    at org.apache.commons.logging.impl.SLF4JLocationAwareLog.debug(SLF4JLocationAwareLog.java:133)
    at net.sf.jasperreports.engine.xml.JRXmlDigesterFactory.createParser(JRXmlDigesterFactory.java:1452)
    at net.sf.jasperreports.engine.xml.JRXmlDigesterFactory.createDigester(JRXmlDigesterFactory.java:1432)
    at net.sf.jasperreports.engine.xml.JRXmlLoader.load(JRXmlLoader.java:262)
    at net.sf.jasperreports.engine.xml.JRXmlLoader.load(JRXmlLoader.java:247)
    at net.sf.jasperreports.engine.JasperCompileManager.compile(JasperCompileManager.java:338)
    at net.sf.jasperreports.engine.JasperCompileManager.compileReport(JasperCompileManager.java:605)
    at report.JasperTableExample.main(JasperTableExample.java:70)
Java Result: 1

Link to comment
Share on other sites

  • Replies 0
  • Created
  • Last Reply

Top Posters In This Topic

Popular Days

Top Posters In This Topic

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...