dnvsrikanth Posted August 13, 2007 Share Posted August 13, 2007 hi all, While generating a report which retrieves data from SQL Server 2000 and displaying it in PDF format , a NullPointerException is being thrown.I cant resolve why the exception is being generated. Can any body help me out in this regard.... I am giving the servlet code:package com; import java.io.*;import java.sql.Connection;import java.sql.DriverManager;import java.util.HashMap; import javax.servlet.*;import javax.servlet.http.*;import net.sf.jasperreports.engine.JRException;import net.sf.jasperreports.engine.JasperRunManager; /** * * @author srikanth.d * @version */public class ReporDtataSource extends HttpServlet { protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { Connection con; ServletOutputStream servletOutputStream = response.getOutputStream(); InputStream inputStream = null; HashMap hm= new HashMap(); inputStream = getServletConfig().getServletContext().getResourceAsStream("/report.jrxml"); try { Class.forName("net.sourceforge.jtds.jdbc.Driver"); con = DriverManager.getConnection("jdbc:jtds:sqlserver://10.2.84.204/Metrics_Commercial_Prototype_20;instance=","metric","metric"); JasperRunManager.runReportToPdfStream(inputStream, servletOutputStream,hm,con); HashMap()); con.close(); response.setContentType("application/pdf"); servletOutputStream.flush(); servletOutputStream.close(); }catch(Exception e){ e.printStackTrace(); } }} Link to comment Share on other sites More sharing options...
csbac Posted August 13, 2007 Share Posted August 13, 2007 Hi!Maybe you should also post the stack trace, so we can see /where/ the NullPtrException happens?Yours,Sebastian Link to comment Share on other sites More sharing options...
dnvsrikanth Posted August 14, 2007 Author Share Posted August 14, 2007 hiThanks for ur help.....I am herewith posting stack trace..... java.lang.NullPointerException at java.io.ObjectInputStream$PeekInputStream.read(ObjectInputStream.java:2264) at java.io.ObjectInputStream$PeekInputStream.readFully(ObjectInputStream.java:2277) at java.io.ObjectInputStream$BlockDataInputStream.readShort(ObjectInputStream.java:2748) at java.io.ObjectInputStream.readStreamHeader(ObjectInputStream.java:780) at java.io.ObjectInputStream.<init>(ObjectInputStream.java:280) at net.sf.jasperreports.engine.util.JRLoader.loadObject(JRLoader.java:191) at net.sf.jasperreports.engine.JasperFillManager.fillReport(JasperFillManager.java:361) at net.sf.jasperreports.engine.JasperRunManager.runReportToPdfStream(JasperRunManager.java:163) at com.ReporDtataSource.doGet(ReporDtataSource.java:50) at javax.servlet.http.HttpServlet.service(HttpServlet.java:689) at javax.servlet.http.HttpServlet.service(HttpServlet.java:802) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:252) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173) at org.netbeans.modules.web.monitor.server.MonitorFilter.doFilter(MonitorFilter.java:368) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:202) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173) at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:213) at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:178) at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:126) at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:105) at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:107) at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:148) at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:869) at org.apache.coyote.http11.Http11BaseProtocol$Http11ConnectionHandler.processConnection(Http11BaseProtocol.java:664) at org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:527) at org.apache.tomcat.util.net.LeaderFollowerWorkerThread.runIt(LeaderFollowerWorkerThread.java:80) at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:684) at java.lang.Thread.run(Thread.java:619) Link to comment Share on other sites More sharing options...
gbegley Posted August 14, 2007 Share Posted August 14, 2007 .jasper file is the serialized report object, but it looks like you are using the object loader to load the the Report definition. You should be passing an input stream to a compiled report (.jasper) file. Instead, you could compile the report at runtime like this: JasperReport report = JasperCompileManager.compileReport( jrXMLFileUrl.openStream() ); then pass the report object to the run manager.HTHGeoff Link to comment Share on other sites More sharing options...
gbegley Posted August 14, 2007 Share Posted August 14, 2007 However with the NPE from from inputstream.read are you sure the file exists where your program is looking? Link to comment Share on other sites More sharing options...
gbegley Posted August 14, 2007 Share Posted August 14, 2007 also, you'll probably need to set the contentType of the ServletResponse to pdf res.setContentType( "application/pdf" ) Link to comment Share on other sites More sharing options...
dnvsrikanth Posted August 14, 2007 Author Share Posted August 14, 2007 hiThanks for your quick reply.... Yes...the file exists in the specified location. I've already set set the Contex to application/pdf. So do I need to give .jasper file to the input stream if its already compiled and ready??? Link to comment Share on other sites More sharing options...
dnvsrikanth Posted August 15, 2007 Author Share Posted August 15, 2007 The problem still exists...Can anyone please solve this problem??? Link to comment Share on other sites More sharing options...
csbac Posted August 15, 2007 Share Posted August 15, 2007 Hi!I thought the answer was already posted here ... either load the .jasper file with JasperRunManager.runReportToPdfStream(...),or the .jrxml with JasperReport report = JasperCompileManager.compileReport(...); Or did you already try both versions, and the NPE still persists? Yours,Sebastian Link to comment Share on other sites More sharing options...
dnvsrikanth Posted August 16, 2007 Author Share Posted August 16, 2007 thank you...its working....:cheer: Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now