0

getting error " java.lang.NullPointerException " in jasper reports.

asked 2012-09-24 05:50:02 +0800

swati123 gravatar image swati123
66

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.

delete flag offensive retag edit

3 Replies

Sort by ยป oldest newest

answered 2012-09-24 10:29:48 +0800

swati123 gravatar image swati123
66

hi.

I am using ireport 4.7 and imported all jar files in WEB-INF/lib directory.
Still the problem is persisting.
Is any other changes required.
please help me.

thanks.

link publish delete flag offensive edit

answered 2012-09-28 03:32:27 +0800

iantsai gravatar image iantsai
2755 1

Could you post your stack trace?
which object was NULL but it shouldn't ?

link publish delete flag offensive edit

answered 2012-09-28 05:30:16 +0800

swati123 gravatar image swati123
66

hi..

my problem is solved..
Actually I had to import the jar files of same version,which ireport version belongs.
and remove language=groovy from xml page of ireport.
Now my report is working fine..

thanks.

link publish delete flag offensive edit
Your reply
Please start posting your answer anonymously - your answer will be saved within the current session and published after you log in or create a new account. Please try to give a substantial answer, for discussions, please use comments and please do remember to vote (after you log in)!

[hide preview]

Question tools

Follow

RSS

Stats

Asked: 2012-09-24 05:50:02 +0800

Seen: 168 times

Last updated: Sep 28 '12

Support Options
  • Email Support
  • Training
  • Consulting
  • Outsourcing
Learn More