public static void main(String[] args) throws SQLException, JRException, FileNotFoundException {
// Coloquei o arquivo na raiz do projeto Maven
String fileName ="gasto_por_mes.jasper";
String fileNamePdf = "gastos_por_mes.pdf";
try {
Connection connection = new ConnectionFactory().getConnection();
System.out.println("conexao efetuada");
/* Não consegue compilar aqui, então coloquei o arquivo gerado no próprio iReport */
// JasperCompileManager.compileReportToFile("gasto_por_mes.jrxml");
// JasperCompileManager.compileReportToFile("subReport_Contas.jrxml");
Map<String, Object> parameters = new HashMap<String, Object>();
JasperPrint jasperPrint = JasperFillManager.fillReport(fileName, parameters, connection);
JRExporter exporter = new JRPdfExporter();
exporter.setParameter(JRExporterParameter.JASPER_PRINT, jasperPrint);
exporter.setParameter(JRExporterParameter.OUTPUT_STREAM, new FileOutputStream(fileNamePdf));
exporter.exportReport();
connection.close();
} catch (Exception e) {
System.out.println("Problema na conexao");
e.printStackTrace();
}
}
java.lang.NullPointerException at net.sf.jasperreports.engine.fill.JRVerticalFiller.fillReport(JRVerticalFiller.java:168) at net.sf.jasperreports.engine.fill.JRBaseFiller.fill(JRBaseFiller.java:963) at net.sf.jasperreports.engine.fill.JRBaseFiller.fill(JRBaseFiller.java:873) at net.sf.jasperreports.engine.fill.JRFiller.fill(JRFiller.java:87) at net.sf.jasperreports.engine.JasperFillManager.fill(JasperFillManager.java:287) at net.sf.jasperreports.engine.JasperFillManager.fillReport(JasperFillManager.java:760) at br.fc.teste.TestarRelatorio.main(TestarRelatorio.java:34)