Jump to content
Changes to the Jaspersoft community edition download ×

Jasper Reports Error


2005 IR Help

Recommended Posts

By: Devavratt - devavratt

Jasper Reports Error

2004-12-13 22:23

Hello,

This is the error I see when I try to produce a report thru jasper

report -

----------------------------

java.io.StreamCorruptedException: invalid stream header

at

java.io.ObjectInputStream.readStreamHeader(ObjectInputStream.java:737)

at java.io.ObjectInputStream.<init>(ObjectInputStream.java:253)

at

net.sf.jasperreports.engine.util.JRLoader.loadObject(JRLoader.java:128)

at

net.sf.jasperreports.engine.JasperFillManager.fillReport(JasperFillManager.j

ava:386)

at JasperTest.JasperTestMethod(JasperTest.java:70)

at JasperTest.main(JasperTest.java:84)

 

NESTED BY :

java.io.StreamCorruptedException: invalid stream header

at

java.io.ObjectInputStream.readStreamHeader(ObjectInputStream.java:737)

at java.io.ObjectInputStream.<init>(ObjectInputStream.java:253)

at

net.sf.jasperreports.engine.util.JRLoader.loadObject(JRLoader.java:128)

at

net.sf.jasperreports.engine.JasperFillManager.fillReport(JasperFillManager.j

ava:386)

at JasperTest.JasperTestMethod(JasperTest.java:70)

at JasperTest.main(JasperTest.java:84)

 

NESTED BY :

net.sf.jasperreports.engine.JRException: Error loading object from file :

Test_1.jrxml

at

net.sf.jasperreports.engine.util.JRLoader.loadObject(JRLoader.java:133)

at

net.sf.jasperreports.engine.JasperFillManager.fillReport(JasperFillManager.j

ava:386)

at JasperTest.JasperTestMethod(JasperTest.java:70)

at JasperTest.main(JasperTest.java:84)

Caused by: java.io.StreamCorruptedException: invalid stream header

at

java.io.ObjectInputStream.readStreamHeader(ObjectInputStream.java:737)

at java.io.ObjectInputStream.<init>(ObjectInputStream.java:253)

at

net.sf.jasperreports.engine.util.JRLoader.loadObject(JRLoader.java:128)

-------------------------------------

Following is the code snippet I am using -

-------------

import net.sf.jasperreports.engine.*;

import net.sf.jasperreports.engine.JRException;

import net.sf.jasperreports.engine.JasperFillManager;

import net.sf.jasperreports.engine.JRDataSource;

import net.sf.jasperreports.engine.JRResultSetDataSource;

import net.sf.jasperreports.engine.JasperPrint;

import net.sf.jasperreports.engine.JasperExportManager;

 

import java.util.*;

import java.sql.*;

import java.util.Map;

import java.sql.ResultSet;

import java.sql.SQLException;

import java.sql.Connection;

 

public class JasperTest

{

public void JasperTestMethod() {

String strUrl = "jdbc:oracle:thin:@HostMachine:1521:DBName";

String strUserName = "username";

String strPass = "pwd";

String statementQuery = "select * from tableName";

 

try {

Class.forName("oracle.jdbc.driver.OracleDriver");

} catch (ClassNotFoundException e) {

e.printStackTrace();

}

Connection m_Connection = null;

Statement stmt = null;

ResultSet rs = null;

try {

m_Connection = DriverManager.getConnection(strUrl, strUserName,

strPass);

stmt = m_Connection.createStatement();

rs = stmt.executeQuery(statementQuery);

 

} catch (SQLException e) {

e.printStackTrace();

}

try {

JRDataSource dataSource = new JRResultSetDataSource(rs);

Map param = new java.util.HashMap();

param.put("Bonus", new Integer(12000));

param.put("Year", new String("2004"));

JasperPrint print = JasperFillManager.fillReport("Test_1.jrxml",

param, dataSource);

JasperExportManager.exportReportToPdfFile(print, "JasperTest.pdf");

}

catch (JRException e) {

System.out.println("JRException - "+e);

e.printStackTrace();

}

}

public static void main(String args[]){

JasperTest objJR = new JasperTest();

objJR.JasperTestMethod();

}

}

----------

The above code compiles fine without any error, but I get the above error

when I try to run it.

The .jrxml path and DB connection are fine.

Suggest modifications in the above code.

 

 

 

 

By: sergey_v - sergey_v

RE: Jasper Reports Error

2004-12-14 02:45

You should first compile xml file into .jasper, then fill it, then export to pdf or html, etc. or print. Therefore, your line JasperFillManager.fillReport("Test_1.jrxml",... is wrong. fillReport should operate on compiled .jasper file.

Link to comment
Share on other sites

  • Replies 0
  • Created
  • Last Reply

Top Posters In This Topic

Popular Days

Top Posters In This Topic

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