-
FEATURED COMPONENTS
First time here? Check out the FAQ!
hi all,
I have written the following code to generate reports.but I am getting error " java.lang.NullPointerException" .
<?page title="new page title" contentType="text/html;charset=UTF-8" style="height:100%" ?>
<zk>
<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 javax.sql.*;
import com.mysql.jdbc.Driver.*;
import java.util.*;
import java.lang.*;
import net.sf.jasperreports.engine.design.*;
import net.sf.jasperreports.engine.JREmptyDataSource;
import net.sf.jasperreports.engine.JRException;
import net.sf.jasperreports.engine.JRPropertiesMap;
import org.zkoss.util.media.AMedia;
import net.sf.jasperreports.engine.JasperRunManager;
void doReport()
{
try
{
InputStream is = null;
//generate report pdf stream
final Execution exec = Executions.getCurrent();
is = exec.getDesktop().getWebApp().getResourceAsStream(exec.toAbsoluteURI("/WEB-INF/test.jasper", false));
alert(is);
final Map params = new HashMap();
params.put("ReportTitle", "The First Jasper Report Ever");
//params.put("MaxOrderID", new Integer(10500));
alert(getConnection());
alert(1);
final byte[] buf =
JasperRunManager.runReportToPdf(is, params, getConnection());
alert(2);
//prepare the AMedia for iframe
final InputStream mediais = new ByteArrayInputStream(buf);
final AMedia amedia = new AMedia("/WEB-INF/test.pdf", "pdf", "application/pdf", mediais);
alert(4);
//set iframe content
report.setContent(amedia);
alert(5);
}
catch (Exception ex) {
throw new RuntimeException(ex);
} finally {
if (is != null) {
is.close();
}
}
}
Connection getConnection()
{
//Change these settings according to your local configuration
String driver = "com.mysql.jdbc.Driver";
String connectString = "jdbc:mysql://localhost:3306/stock";
String user = "root";
String password = "123456";
try
{
Class.forName(driver);
Connection conn = DriverManager.getConnection(connectString, user, password);
return conn;
}
catch (Exception ms)
{
ms.printStackTrace();
return null;
}
}
</zscript>
</window>
</zk>
please help me.Compiler is reading upto alert(1), but after that it is showing nothing.
Thanks.
Asked: 2012-09-24 05:50:02 +0800
Seen: 168 times
Last updated: Sep 28 '12