Jump to content

Problems with JasperReports in Eclipse


Muyerina

Recommended Posts

Hello everybody:

I have a problem in my Java application and i dont have any idea how can solutionate it.

I have 2 kind of reports in my application. One kind works with a mysql database and the other kind with SQL Server 2005.

The reports that works with mysql are OK, but the other reports have a problem. When i execute it with iReport they works correctly, but in my Java Application they dont run, the application gives me the following exception:

error: java.lang.ClassCastException: cannot assign instance of net.sf.jasperreports.engine.base.JRBaseStaticText to field net.sf.jasperreports.engine.base.JRBaseLineBox.boxContainer of type net.sf.jasperreports.engine.JRBoxContainer in instance of net.sf.jasperreports.engine.base.JRBaseLineBox

This exception appears in the method that tries to create the .jrprint file.

In my application I'm using the same driver and data conection than iReport, so i dont know what im doing wrong... any idea?

Thank you very much

Link to comment
Share on other sites

  • Replies 10
  • Created
  • Last Reply

Top Posters In This Topic

Hello again

I have solved my problem, thank you very much. The solution was in the version of the libraries that i was using.

Later, i had the following error:

net.sf.jasperreports.engine.JRRuntimeException: Could not create chart customizer instance.

I solved it including a new jar in the Eclipse folder "lib" with the customizer class that i was using. Before that i was working with the customizer class in the same folder that the .jasper file.

I hope this helps you!

Link to comment
Share on other sites

  • 1 year later...

Hello,

I am new to JasperReport. How you open jasperReports in Eclipse? Do you know what is the source file for JasperReport? xml or Jrxml or both? I found our old rpt source files are all xml files. but looks like iReport expect Jrxml as source.

 

Thanks in advance

Link to comment
Share on other sites

Hello Weihuo:

iReport works with files .jrxml, wich are documents in xml format that uses the JasperReports libraries. You can work with iReport without touching Eclipse. When you have your report template you can generate it and you obtain the .jasper file.

With that kind of file (.jasper) generated in iReport you go to your proyect in Eclipse. You also have to include the JasperReports libraries to execute the reports and fill the template with the correct data.

If you want you can include the .jrxml file in Eclipse and generate the .jasper file with java code.

Link to comment
Share on other sites

Thanks Muyerina.

I am currently working on updating existing report. I found all my reports are very old version of JasperReport since there are only xml files for the source. If I use most current version of iReport to build the report by copying xml to Jrxml, I can get .jasper file. But my java code: JRLoader.loadObject() complains " cannot load the jasper file"....

I tried all versions of iReport  from V3.5 to V0.2.0. Finally I found that iReport-0.2.2 seems work for me. But when I added DB2 to the connection, I encounted the same issue as hsbgowd had. I already add db2jcc.jar and db2jcc_license_cu.jar in my classpath. my db2 version is 8.1.7 also very old.

another question is for queryString tag: how can I write 2 seperate sqls? and how can I write different query based on passed in  parameter is null or not?

Could you please help me?

Thanks in advance.

Wei

Link to comment
Share on other sites

When you try to open your old version of proyect with a newer version of iReport I think it update your proyect automaticaly, doesn't it? If it doesnt do that maybe you have to copy the xml into a jrxml like you say.

About your error in Java (cannot load the jasper file) Are you sure it doesn't work due to the version? Maybe the code cannot find the jasper file because it is in a diferent part of your code or something.
In iReport you can execute your report with the active conection, so you can check the jasper libraries and the data base conector works fine. If the report looks well you should check the java code and the Eclipse proyect. If you change your version of report you have to update the libraries of your proyect too, maybe you still have the old ones.

To write 2 separate sqls you have to use subreports in your report.

To use parameters in your querys you have to create it in your report, and then use it in your querys like this: $P{parameter_name}

Link to comment
Share on other sites

Hello Muyerna,

Thank you very much for your reply.

1. newer version can only load Jrxml file in order to use designer and preview(build). I new an empty report which auto create a Jrxml outline, then I copy my existing xml into the Jrxml. the designer will display the report layout. once I click preview with empty datasource(since I have db2 connection issue), it will display PDF view of report. at the same time it will generate .jasper file. if I use this new jasper file even I did not change anything. It can not be loaded in my java code. I already get corresponding version of jasperreports jar.

2. I will try subreport for multiple queries;

3. I notice that when writing sql in queryString tag, we can use case ... when .. then.. else... end, but all is used in select clause not where clause. for example I would like to do the following action:

select * from table_a

where table_a.id1 = $P{parameter_id1}

if $P{parameter_id2} is not null

and table_a.id2 = $P{parameter_id2}

How should I write the query like above case?

Thanks in advance.

Wei

Link to comment
Share on other sites

Hello Muyerna,

one more question: Can I pass the entir query to jasperReport? I tried but I failed:

I pass the query from java code to report as a parameter. In <queryString><![CDATA[ $P!{param_query} ]]</queryString>

in later report, I mention the field in the query:

<field name="com_due_clnt" class="java.lang.Double"/>

it complains: Unable to get value for field 'com_due_clnt' of class 'java.lang.Double'.

Thanks.

 

Wei

Link to comment
Share on other sites

  • 1 year later...

Hi,

Thanks your soluction.I update my jasperreport file to version 3.7.6 and ireport version is the same,but I run my java application and still got this exception:

java.lang.ClassCastException: cannot assign instance of net.sf.jasperreports.engine.base.JRBaseStaticText to field net.sf.jasperreports.engine.base.JRBaseLineBox.boxContainer of type net.sf.jasperreports.engine.JRBoxContainer in instance of net.sf.jasperreports.engine.base.JRBaseLineBox

 

I have no any idea about this exception,would you please tell me the detail solution.

 

Thank you very much.

Link to comment
Share on other sites

  • 1 year later...

Hello every body,

i am beginner with jasperreport.

i follow one tutorial ,i craete a template with iReport, i compile it to have a .jasper documents to use it in my class java.

after i create an java application,but it does not work ,here is the message displayed (sorry for my english)

 

run:
Exception in thread "main" java.lang.NullPointerException
    at java.io.ObjectInputStream$PeekInputStream.read(ObjectInputStream.java:2265)
    at java.io.ObjectInputStream$PeekInputStream.readFully(ObjectInputStream.java:2278)
    at java.io.ObjectInputStream$BlockDataInputStream.readShort(ObjectInputStream.java:2749)
    at java.io.ObjectInputStream.readStreamHeader(ObjectInputStream.java:779)
    at java.io.ObjectInputStream.<init>(ObjectInputStream.java:279)
    at net.sf.jasperreports.engine.util.ContextClassLoaderObjectInputStream.<init>(ContextClassLoaderObjectInputStream.java:53)
    at net.sf.jasperreports.engine.util.JRLoader.loadObject(JRLoader.java:214)
    at net.sf.jasperreports.engine.JasperFillManager.fill(JasperFillManager.java:405)
    at net.sf.jasperreports.engine.JasperFillManager.fillReport(JasperFillManager.java:824)
    at id.hans.employee.application.Mainclass.showReport(Mainclass.java:59)
    at id.hans.employee.application.Mainclass.main(Mainclass.java:83)



Post Edited by jasmine22 at 06/29/2012 17:10
Link to comment
Share on other sites

  • 2 weeks later...

Hi,

I have gone through ur form.

And i think may be here i can solve my problem, so i am sharing it with you all.

Actually, i have created a report in iReport .jrxml and on compiling i am getting jasper file of that.

i have created that folder on my desktop.

Now, in eclipse i am using jsf in that when i try to open a iReport viewer .the viewer get opens but it gives null value where it has to give the value that is filled in the form.

thanks in adavance.

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