Pessoal estou tentando criar um relatorio apartir de uma classe java, mas estou tomando null pointer
Exception in thread "main" java.lang.NullPointerException
at java.io.ObjectInputStream$PeekInputStream.read(ObjectInputStream.java:2266)
at java.io.ObjectInputStream$PeekInputStream.readFully(ObjectInputStream.java:2279)
fui verificar e vi que minha variavel realJasper esta nula, é a forma como estou trazendo o arquivo xml ? fiz turo no ireport + netbeans la funciona blz, mas agora não consigo montar a classe que gera o pdf, podem me ajudar ?
public class GeraRel {
public void GeraRelatorio() throws JRException {
//caminho do jasper
String jasper = "K:\javaApplication\nfe\src\nfe\relatorios\danfe.jasper";
String xmlFileName = "K:\javaApplication\nfe\src\nfe\relatorios\NF-e.xml";
// Stream com o .jasper
InputStream relJasper = getClass().getResourceAsStream(jasper);
//data source que carrega um xml
JRXmlDataSource jr = new JRXmlDataSource(xmlFileName);
/* HashMap de parâmetros utilizados no relatório. Sempre instanciados */
Map parameters = new HashMap();
JasperPrint impressao = JasperManager.fillReport(relJasper, parameters, jr );
// impressao = JasperFillManager.fillReport(relJasper, parameters, jr);
JasperViewer viewer = new JasperViewer(impressao, true);
viewer.setVisible(true);
}
public static void main(String args[]) throws JRException {
new GeraRel().GeraRelatorio();
}
resolvi pessoal vou postar aqui como ficaou funcionando, abraços e obrigado mesmo ninguem tendo respondido
public class JasperTeste {
public static void main(String args[]) throws JRException {
String jasper = "K:\javaApplication\nfe\src\nfe\relatorios\danfe.jasper";
String xmlFileName = "K:\javaApplication\nfe\src\nfe\relatorios\NF-e.xml";
String output = "K:\javaApplication\nfe\src\nfe\relatorios\danfe.pdf";
HashMap hm = new HashMap();
JRXmlDataSource jrxds = new JRXmlDataSource(xmlFileName);
try {
JasperPrint print = JasperFillManager.fillReport(jasper, hm, jrxds);
JRExporter exporter = new JRPdfExporter();
exporter.setParameter(JRExporterParameter.OUTPUT_FILE_NAME, output);
exporter.setParameter(JRExporterParameter.JASPER_PRINT, print);
exporter.exportReport();
System.out.println("criado arquivo" + output);
} catch (JRException e) {
e.printStackTrace();
System.exit(1);
} catch (Exception e) {
e.printStackTrace();
}
}
}