-
FEATURED COMPONENTS
First time here? Check out the FAQ!
<?page style="height:100%" ?>
<window width="100%" height="100%">
<borderlayout height="100%">
<north maxsize="24" size="24" border="0">
<button label="Report!" onClick="doReport()"/>
</north>
<center border="none" flex="true">
<iframe id="report" />
</center>
</borderlayout>
<zscript>
import java.io.*;
import java.sql.*;
import java.util.*;
import org.zkoss.util.media.AMedia;
import net.sf.jasperreports.engine.JasperRunManager;
void doReport() {
try {
//generate report pdf stream
alert(1);
InputStream is = Thread.currentThread().getContextClassLoader().getResourceAsStream("report3.jasper");
alert(2);
final Map params = new HashMap();
params.put("ReportTitle", "The First Jasper Report Ever");
params.put("MaxOrderID", 10500);
alert(3);
alert(is);
final byte[] buf =JasperRunManager.runReportToPdf(is, params, getConnection());
alert(4);
//prepare the AMedia for iframe
final InputStream mediais = new ByteArrayInputStream(buf);
final AMedia amedia = new AMedia("FirstReport.pdf", "pdf", "application/pdf", mediais);
//set iframe content
report.setContent(amedia);
} catch (Exception ex) {
throw new RuntimeException(ex);
} finally {
if (is != null) {
is.close();
}
}
}
private static Connection getConnection()
throws ClassNotFoundException, SQLException
{
//Change these settings according to your local configuration
String driver = "com.mysql.jdbc.Driver";
String connectString = "jdbc:mysql://localhost:3306/etrack";
String user = "root";
String password = "satya";
Class.forName(driver);
Connection conn = DriverManager.getConnection(connectString, user, password);
return conn;
}
</zscript>
</window>
i m new to jasper report
my code is this i m getting a null pointer Exception ...
plz tell me .....
how can i do this
I also tried with the below code then also it throws a nullPointer Exception
plz help me.....
____________________________________________________________
<?page style="height:100%" ?>
<window width="100%" height="100%">
<borderlayout height="100%">
<north maxsize="24" size="24" border="0">
<button label="Report!" onClick="doReport()"/>
</north>
<center border="none" flex="true">
<iframe id="report" />
</center>
</borderlayout>
<zscript>
import java.io.*;
import java.sql.*;
import java.util.*;
import org.zkoss.util.media.AMedia;
import net.sf.jasperreports.engine.JasperRunManager;
import net.sf.jasperreports.engine.JREmptyDataSource;
import net.sf.jasperreports.engine.JRException;
void doReport() {
InputStream is=null;
try {
//generate report pdf stream
alert(1);
final Execution exec=Executions.getCurrent();
is = exec.getDesktop().getWebApp().getResourceAsStream(exec.toAbsoluteURI("/WEB-INF/jasper/report3.jasper",false));
alert(2);
// final Map params = new HashMap();
// params.put("ReportTitle", "The First Jasper Report Ever");
alert(3);
alert(is);
final byte[] buf =JasperRunManager.runReportToPdf(is, new HashMap(), new JREmptyDataSource());
alert(4);
//prepare the AMedia for iframe
final InputStream mediais = new ByteArrayInputStream(buf);
final AMedia amedia = new AMedia("FirstReport.pdf", "pdf", "application/pdf", mediais);
//set iframe content
report.setContent(amedia);
} catch (Exception ex) {
throw new RuntimeException(ex);
} finally {
if (is != null) {
is.close();
}
}
}
private static Connection getConnection()
throws ClassNotFoundException, SQLException
{
//Change these settings according to your local configuration
String driver = "com.mysql.jdbc.Driver";
String connectString = "jdbc:mysql://localhost:3306/etrack";
String user = "root";
String password = "satya";
Class.forName(driver);
Connection conn = DriverManager.getConnection(connectString, user, password);
return conn;
}
</zscript>
</window>
Check the exception message to know which variable is null
Please post your error log. (we are not compiler)
/Jumper
INFO: Source is changed: /jasper.zul
May 11, 2009 1:12:37 PM org.zkoss.zk.ui.impl.UiEngineImpl handleError:1107
SEVERE: >>java.lang.RuntimeException: java.lang.NullPointerException
>>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.JasperFillManager.fillReport(JasperFillManager.java:361)
>> at net.sf.jasperreports.engine.JasperRunManager.runReportToPdf(JasperRunManager.java:242)
>> 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 bsh.Reflect.invokeMethod(Unknown Source)
>> at bsh.Reflect.invokeStaticMethod(Unknown Source)
Hi,
It seems to be an issue of JasperReport, please search here with the text "JRPropertiesMap.java:185"
/Jumper
Asked: 2009-05-10 07:08:22 +0800
Seen: 2,605 times
Last updated: Dec 24 '10