Jump to content
Changes to the Jaspersoft community edition download ×

displaying Graphic Element in JasperReports


2005 IR Help

Recommended Posts

By: Dhinesh Kumar P - dhindu

displaying Graphic Element in JasperReports

2004-10-29 03:48

hi,

Im new to JasperReports. Im practicing demo samples alterreport. I created a report having a static text, 1 rectangle, 1 round rectangle and 1 ellipse using iReport. when i run it using iReport, it ran successfully. But when im trying to fill the jrxml file generated by iReport using JasperReports, im getting null pointer exception when im trying to retrieve the rectangle. println's shows that the .jasper file is having only text and not any graphic element.

My doubts are

1. How to get a graphic element in the .jasper report? Do i need to include any class to include graphic elements in the report?

 

2. When we have to include a scriplet class tag in the .jrxml file? what's the significance of scriplet class in JasperReports?

 

the exception is simple but i couldn't found out.

 

here is my java program:

try {

// cpmpilation of jrxml file

System.out.println("going to compile");

JasperCompileManager.compileReportToFile("E:\JasperReports/reports/runtimereport/RunTimeReport.jrxml");

System.out.println("compilation successful");

//filling the jasper file

File objFile = new File(objSourceFile1);

JasperReport objJasperReport = (JasperReport)JRLoader.loadObject("E:\JasperReports/reports/runtimereport/RunTimeReport.jasper");

 

List list = objJasperReport.getTitle().getChildren();

Iterator iterator = list.iterator();

while(iterator.hasNext()) {

System.out.println("iterator.next().getClass() = " + iterator.next().getClass());

}

 

JRRectangle objJRRectangle = (JRRectangle)objJasperReport.getTitle().getElementByKey("FirstRectangle");

objJRRectangle.setBackcolor(new Color((int)(16000000 * Math.random())));

objJRRectangle.setForecolor(new Color((int)(16000345 * Math.random())));

 

objJRRectangle = (JRRectangle)objJasperReport.getTitle().getElementByKey("SecondRectangle");

objJRRectangle.setBackcolor(new Color((int)(25000000 * Math.random())));

objJRRectangle.setForecolor(new Color((int)(25000345 * Math.random())));

 

JREllipse objJREllipse = (JREllipse)objJasperReport.getTitle().getElementByKey("FirstEllipse");

objJREllipse.setBackcolor(new Color((int)(10000000 * Math.random())));

objJREllipse.setForecolor(new Color((int)(10000000 * Math.random())));

 

 

JasperPrint objJasperPrint = JasperFillManager.fillReport(objJasperReport, null, (Connection)null);

 

File objDestFile = new File(objFile.getParent(), objJasperReport.getName() + ".jrprint");

JRSaver.saveObject(objJasperPrint, objDestFile);

 

//exporting the file

JasperExportManager.exportReportToHtmlFile(objJasperPrint, objJasperReport.getName());

System.out.println("successful");

} catch (JRException e) {

e.printStackTrace();

} catch (Exception e) {

e.printStackTrace();

}

 

the stacktrace is:

java.lang.NullPointerException

at runtimereport.RunTimeReport.main(RunTimeReport.java:58)

 

the jrxml file generated by ireport:

<?xml version="1.0" encoding="UTF-8" ?>

<!-- Created with iReport - A designer for JasperReports -->

<!DOCTYPE jasperReport PUBLIC "//JasperReports//DTD Report Design//EN" "http://jasperreports.sourceforge.net/dtds/jasperreport.dtd">

<jasperReport

name="RuntimeReport"

columnCount="1"

printOrder="Vertical"

orientation="Portrait"

pageWidth="595"

pageHeight="842"

columnWidth="535"

columnSpacing="0"

leftMargin="28"

rightMargin="14"

topMargin="14"

bottomMargin="14"

whenNoDataType="NoPages"

isTitleNewPage="false"

isSummaryNewPage="false">

<property name="ireport.scriptlethandling" value="0" />

<background>

<band height="0" isSplitAllowed="true" >

</band>

</background>

<title>

<band height="64" isSplitAllowed="true" >

</band>

</title>

<pageHeader>

<band height="50" isSplitAllowed="true" >

</band>

</pageHeader>

<columnHeader>

<band height="30" isSplitAllowed="true" >

</band>

</columnHeader>

<detail>

<band height="100" isSplitAllowed="true" >

<rectangle radius="5" >

<reportElement

mode="Opaque"

x="32"

y="22"

width="100"

height="50"

forecolor="#FF3333"

backcolor="#00CCFF"

key="FirstRectangle"

stretchType="NoStretch"

positionType="FixRelativeToTop"

isPrintRepeatedValues="true"

isRemoveLineWhenBlank="false"

isPrintInFirstWholeBand="false"

isPrintWhenDetailOverflows="false"/>

<graphicElement stretchType="NoStretch" pen="1Point" fill="Solid" />

</rectangle>

<rectangle radius="20" >

<reportElement

mode="Opaque"

x="213"

y="22"

width="100"

height="50"

forecolor="#000000"

backcolor="#FFFFFF"

key="SecondRectangle"

stretchType="NoStretch"

positionType="FixRelativeToTop"

isPrintRepeatedValues="true"

isRemoveLineWhenBlank="false"

isPrintInFirstWholeBand="false"

isPrintWhenDetailOverflows="false"/>

<graphicElement stretchType="NoStretch" pen="2Point" fill="Solid" />

</rectangle>

<ellipse>

<reportElement

mode="Opaque"

x="397"

y="21"

width="100"

height="50"

forecolor="#000000"

backcolor="#FFFFFF"

key="FirstEllipse"

stretchType="NoStretch"

positionType="FixRelativeToTop"

isPrintRepeatedValues="true"

isRemoveLineWhenBlank="false"

isPrintInFirstWholeBand="false"

isPrintWhenDetailOverflows="false"/>

<graphicElement stretchType="NoStretch" pen="Thin" fill="Solid" />

</ellipse>

</band>

</detail>

<columnFooter>

<band height="30" isSplitAllowed="true" >

</band>

</columnFooter>

<pageFooter>

<band height="50" isSplitAllowed="true" >

</band>

</pageFooter>

<summary>

<band height="56" isSplitAllowed="true" >

</band>

</summary>

</jasperReport>

 

can someone throw light on this?

 

Thanks in advance,

Dhinesh Kumar P

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