File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Other Open Source Projects and the fly likes JasperReport problem Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Products » Other Open Source Projects
Bookmark "JasperReport problem" Watch "JasperReport problem" New topic
Author

JasperReport problem

Bojan Ivkovic
Greenhorn

Joined: May 17, 2009
Posts: 7
Hi,

Can anybody help me?

when i try to run my jasper report from java code, I get this message: java.lang.NullPointerException

My code is:

public class ReportO1 {
public static Connection connectDB() {
Connection jdbcConnection = null;
try {
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
jdbcConnection = DriverManager
.getConnection("jdbcdbc:baza","Administrator","SuperAdmin");
} catch (Exception ex) {
String connectMsg = "Could not connect to the database: "
+ ex.getMessage() + " " + ex.getLocalizedMessage();
System.out.println(connectMsg);
}
return jdbcConnection;
}

public static void runReport(String datum) {
Map model = new HashMap();
model.put("datum", datum);
try {JasperReport jasperReport = (JasperReport) JRLoader.loadObject("report01.jasper");
System.out.println(2);
Connection jdbcConnection = connectDB();
System.out.println(3);
JasperPrint jasperPrint = JasperFillManager.fillReport(jasperReport, model, jdbcConnection);
System.out.println(4);
JasperViewer.viewReport(jasperPrint, false);
} catch (Exception ex) {
System.out.print(ex);
}
}
}
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42263
    
  64
In which line does that happen? Which object is null?


Ping & DNS - my free Android networking tools app
Bojan Ivkovic
Greenhorn

Joined: May 17, 2009
Posts: 7
In this line
JasperReport jasperReport = (JasperReport) JRLoader.loadObject("report01.jasper");
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42263
    
  64
Post the complete stack trace. Since no object of your code can be null in that line, it must be something within Jasper. Are you sure Jasper knows where to find "report01.jasper"?
Bojan Ivkovic
Greenhorn

Joined: May 17, 2009
Posts: 7
When I put JasperReport jasperReport = (JasperReport) JRLoader.loadObject("c:\\report01.jasper");

there is same exception.

When i put

JasperDesign jasperDesign = JRXmlLoader
.load(new File("report01.jrxml"));
JasperReport jasperReport = JasperCompileManager
.compileReport(jasperDesign);
Connection jdbcConnection = connectDB();
JasperPrint jasperPrint = JasperFillManager.fillReport(
jasperReport, model, jdbcConnection);
JasperViewer.viewReport(jasperPrint, false);

it works.


I don't want to compile report, just to execute jasper file.
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42263
    
  64
Ulf Dittmer wrote:Post the complete stack trace.
Bojan Ivkovic
Greenhorn

Joined: May 17, 2009
Posts: 7
Sorry i didn't understand you, what is complete stack trace?
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42263
    
  64
Instead of
} catch (Exception ex) {
System.out.print(ex);
}

use
} catch (Exception ex) {
ex.printStackTrace();
}

and post the complete output it prints.
Bojan Ivkovic
Greenhorn

Joined: May 17, 2009
Posts: 7
java.lang.NullPointerException
at net.sf.jasperreports.engine.JRPropertiesMap.readObject(JRPropertiesMap.java:185)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at java.io.ObjectStreamClass.invokeReadObject(Unknown Source)
at java.io.ObjectInputStream.readSerialData(Unknown Source)
at java.io.ObjectInputStream.readOrdinaryObject(Unknown Source)
at java.io.ObjectInputStream.readObject0(Unknown Source)
at java.io.ObjectInputStream.defaultReadFields(Unknown Source)
at java.io.ObjectInputStream.readSerialData(Unknown Source)
at java.io.ObjectInputStream.readOrdinaryObject(Unknown Source)
at java.io.ObjectInputStream.readObject0(Unknown Source)
at java.io.ObjectInputStream.readArray(Unknown Source)
at java.io.ObjectInputStream.readObject0(Unknown Source)
at java.io.ObjectInputStream.defaultReadFields(Unknown Source)
at java.io.ObjectInputStream.readSerialData(Unknown Source)
at java.io.ObjectInputStream.readOrdinaryObject(Unknown Source)
at java.io.ObjectInputStream.readObject0(Unknown Source)
at java.io.ObjectInputStream.defaultReadFields(Unknown Source)
at java.io.ObjectInputStream.readSerialData(Unknown Source)
at java.io.ObjectInputStream.readOrdinaryObject(Unknown Source)
at java.io.ObjectInputStream.readObject0(Unknown Source)
at java.io.ObjectInputStream.readObject(Unknown Source)
at net.sf.jasperreports.engine.util.JRLoader.loadObject(JRLoader.java:192)
at net.sf.jasperreports.engine.JasperManager.loadReport(JasperManager.java:998)
at ReportO1.runReport(ReportO1.java:69)
at FormaZakazivanje.stampajIzvestaj(FormaZakazivanje.java:556)
at FormaZakazivanje.access$7(FormaZakazivanje.java:553)
at FormaZakazivanje$7.actionPerformed(FormaZakazivanje.java:331)
at javax.swing.AbstractButton.fireActionPerformed(Unknown Source)
at javax.swing.AbstractButton$Handler.actionPerformed(Unknown Source)
at javax.swing.DefaultButtonModel.fireActionPerformed(Unknown Source)
at javax.swing.DefaultButtonModel.setPressed(Unknown Source)
at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(Unknown Source)
at java.awt.Component.processMouseEvent(Unknown Source)
at javax.swing.JComponent.processMouseEvent(Unknown Source)
at java.awt.Component.processEvent(Unknown Source)
at java.awt.Container.processEvent(Unknown Source)
at java.awt.Component.dispatchEventImpl(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.LightweightDispatcher.retargetMouseEvent(Unknown Source)
at java.awt.LightweightDispatcher.processMouseEvent(Unknown Source)
at java.awt.LightweightDispatcher.dispatchEvent(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Window.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.EventQueue.dispatchEvent(Unknown Source)
at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.run(Unknown Source)
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: JasperReport problem