Jump to content
Changes to the Jaspersoft community edition download ×

Unable to view the report in pdf format


dnvsrikanth

Recommended Posts

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

  • Replies 9
  • Created
  • Last Reply

Top Posters In This Topic

hi

Thanks 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

.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.

HTH

Geoff

Link to comment
Share on other sites

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

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 account

Sign in

Already have an account? Sign in here.

Sign In Now

×
×
  • Create New...