2006 IR Open Dicussion Posted August 27, 2006 Share Posted August 27, 2006 By: Michael Boeni - mbo Null Pointer when adding image 2006-03-20 08:36Hi all I am trying to insert a chart into a report by handing over a "java.awt.Image" as a parameter. No matter what I do, I get the following exception: ---Exception--- Uncaught error fetching image: java.lang.NullPointerException at sun.awt.image.URLImageSource.getConnection(URLImageSource.java:99) at sun.awt.image.URLImageSource.getDecoder(URLImageSource.java:108) at sun.awt.image.InputStreamImageSource.doFetch(InputStreamImageSource.java:248) at sun.awt.image.ImageFetcher.fetchloop(ImageFetcher.java:172) at sun.awt.image.ImageFetcher.run(ImageFetcher.java:136) java.lang.IllegalArgumentException: Width (-1) and height (-1) cannot be <= 0 at java.awt.image.DirectColorModel.createCompatibleWritableRaster(DirectColorModel.java:999) ---><--- I use the following code to read the image: --- Get the image --- image = Toolkit.getDefaultToolkit().getImage(getClass().getResource("D:\alienbrain\work\jasper_testing\jasper_testing\sample_reports\logo.jpg")); ---><--- And the following code is used to fill and show the report: --- Fill/Show Report --- JasperReport jasperReport; JasperPrint jasperPrint; try { Map parameters = new HashMap(); parameters.put("HITSChart", getImage()); jasperReport = JasperCompileManager.compileReport("sample_reports\connect_hits_top10.jrxml"); jasperPrint = JasperFillManager.fillReport(jasperReport, parameters, new HITSTop10DS()); // JasperExportManager.exportReportToPdfFile(jasperPrint, "sample_reports\connect_test_report1.pdf"); JasperViewer.viewReport(jasperPrint); } catch (JRException ex) { ex.printStackTrace(); } ---><--- And here is the report I am using: --- Report --- <?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="connect_hits_top10" columnCount="1" printOrder="Vertical" orientation="Portrait" pageWidth="595" pageHeight="842" columnWidth="535" columnSpacing="0" leftMargin="30" rightMargin="30" topMargin="20" bottomMargin="20" whenNoDataType="NoPages" isTitleNewPage="false" isSummaryNewPage="false"> <property name="ireport.scriptlethandling" value="0" /> <property name="ireport.encoding" value="UTF-8" /> <import value="java.util.*" /> <import value="net.sf.jasperreports.engine.*" /> <import value="net.sf.jasperreports.engine.data.*" /> <parameter name="HITSChart" isForPrompting="false" class="java.awt.Image"/> <field name="HITSRankingValue" class="java.lang.String"/> <field name="ReportTitle" class="java.lang.String"/> <field name="HITSEntityNameValue" class="java.lang.String"/> <background> <band height="0" isSplitAllowed="true" > </band> </background> <title> <band height="50" isSplitAllowed="true" > <textField isStretchWithOverflow="false" pattern="" isBlankWhenNull="false" evaluationTime="Now" hyperlinkType="None" hyperlinkTarget="Self" > <reportElement mode="Transparent" x="5" y="6" width="404" height="38" forecolor="#000000" backcolor="#FFFFFF" key="textField-2" stretchType="NoStretch" positionType="FixRelativeToTop" isPrintRepeatedValues="true" isRemoveLineWhenBlank="false" isPrintInFirstWholeBand="false" isPrintWhenDetailOverflows="false"/> <box topBorder="None" topBorderColor="#000000" leftBorder="None" leftBorderColor="#000000" rightBorder="None" rightBorderColor="#000000" bottomBorder="None" bottomBorderColor="#000000"/> <textElement textAlignment="Left" verticalAlignment="Top" rotation="None" lineSpacing="Single"> <font fontName="Arial" pdfFontName="Helvetica" size="18" isBold="false" isItalic="false" isUnderline="false" isPdfEmbedded ="false" pdfEncoding ="Cp1252" isStrikeThrough="false" /> </textElement> <textFieldExpression class="java.lang.String"><![CDATA[$F{ReportTitle}]]></textFieldExpression> </textField> <image scaleImage="RetainShape" vAlign="Top" hAlign="Left" isUsingCache="false" evaluationTime="Now" hyperlinkType="None" hyperlinkTarget="Self" > <reportElement mode="Opaque" x="426" y="6" width="106" height="33" forecolor="#000000" backcolor="#FFFFFF" key="logo" stretchType="NoStretch" positionType="FixRelativeToTop" isPrintRepeatedValues="true" isRemoveLineWhenBlank="false" isPrintInFirstWholeBand="false" isPrintWhenDetailOverflows="false"/> <box topBorder="None" topBorderColor="#000000" leftBorder="None" leftBorderColor="#000000" rightBorder="None" rightBorderColor="#000000" bottomBorder="None" bottomBorderColor="#000000"/> <graphicElement stretchType="NoStretch" pen="None" fill="Solid" /> <imageExpression class="java.lang.String"><![CDATA["sample_reports\logo.jpg"]]></imageExpression> </image> </band> </title> <pageHeader> <band height="400" isSplitAllowed="true" > <image scaleImage="RetainShape" vAlign="Middle" hAlign="Center" isLazy="true" isUsingCache="false" evaluationTime="Report" hyperlinkType="None" hyperlinkTarget="Self" > <reportElement mode="Opaque" x="9" y="9" width="520" height="380" forecolor="#000000" backcolor="#FFFFFF" key="HITSChart" stretchType="NoStretch" positionType="FixRelativeToTop" isPrintRepeatedValues="true" isRemoveLineWhenBlank="false" isPrintInFirstWholeBand="false" isPrintWhenDetailOverflows="false"/> <box topBorder="None" topBorderColor="#000000" leftBorder="None" leftBorderColor="#000000" rightBorder="None" rightBorderColor="#000000" bottomBorder="None" bottomBorderColor="#000000"/> <graphicElement stretchType="NoStretch" pen="None" fill="Solid" /> <imageExpression class="java.awt.Image"><![CDATA[$P{HITSChart}]]></imageExpression> </image> </band> </pageHeader> <columnHeader> <band height="30" isSplitAllowed="true" > <staticText> <reportElement mode="Transparent" x="11" y="7" width="74" height="14" forecolor="#000000" backcolor="#FFFFFF" key="staticText-1" stretchType="NoStretch" positionType="FixRelativeToTop" isPrintRepeatedValues="true" isRemoveLineWhenBlank="false" isPrintInFirstWholeBand="false" isPrintWhenDetailOverflows="false"/> <box topBorder="None" topBorderColor="#000000" leftBorder="None" leftBorderColor="#000000" rightBorder="None" rightBorderColor="#000000" bottomBorder="None" bottomBorderColor="#000000"/> <textElement textAlignment="Left" verticalAlignment="Top" rotation="None" lineSpacing="Single"> <font fontName="Arial" pdfFontName="Helvetica" size="10" isBold="false" isItalic="false" isUnderline="false" isPdfEmbedded ="false" pdfEncoding ="Cp1252" isStrikeThrough="false" /> </textElement> <text><![CDATA[HITS Ranking]]></text> </staticText> <staticText> <reportElement mode="Transparent" x="103" y="8" width="80" height="13" forecolor="#000000" backcolor="#FFFFFF" key="staticText-2" stretchType="NoStretch" positionType="FixRelativeToTop" isPrintRepeatedValues="true" isRemoveLineWhenBlank="false" isPrintInFirstWholeBand="false" isPrintWhenDetailOverflows="false"/> <box topBorder="None" topBorderColor="#000000" leftBorder="None" leftBorderColor="#000000" rightBorder="None" rightBorderColor="#000000" bottomBorder="None" bottomBorderColor="#000000"/> <textElement textAlignment="Left" verticalAlignment="Top" rotation="None" lineSpacing="Single"> <font fontName="Arial" pdfFontName="Helvetica" size="10" isBold="false" isItalic="false" isUnderline="false" isPdfEmbedded ="false" pdfEncoding ="Cp1252" isStrikeThrough="false" /> </textElement> <text><![CDATA[Entity Name]]></text> </staticText> </band> </columnHeader> <detail> <band height="17" isSplitAllowed="true" > <textField isStretchWithOverflow="false" pattern="" isBlankWhenNull="false" evaluationTime="Now" hyperlinkType="None" hyperlinkTarget="Self" > <reportElement mode="Transparent" x="11" y="2" width="74" height="15" forecolor="#000000" backcolor="#FFFFFF" key="textField-1" stretchType="NoStretch" positionType="FixRelativeToTop" isPrintRepeatedValues="true" isRemoveLineWhenBlank="false" isPrintInFirstWholeBand="false" isPrintWhenDetailOverflows="false"/> <box topBorder="None" topBorderColor="#000000" leftBorder="None" leftBorderColor="#000000" rightBorder="None" rightBorderColor="#000000" bottomBorder="None" bottomBorderColor="#000000"/> <textElement textAlignment="Left" verticalAlignment="Top" rotation="None" lineSpacing="Single"> <font fontName="Arial" pdfFontName="Helvetica" size="10" isBold="false" isItalic="false" isUnderline="false" isPdfEmbedded ="false" pdfEncoding ="Cp1252" isStrikeThrough="false" /> </textElement> <textFieldExpression class="java.lang.String"><![CDATA[$F{HITSRankingValue}]]></textFieldExpression> </textField> <textField isStretchWithOverflow="false" pattern="" isBlankWhenNull="false" evaluationTime="Now" hyperlinkType="None" hyperlinkTarget="Self" > <reportElement mode="Transparent" x="103" y="3" width="80" height="12" forecolor="#000000" backcolor="#FFFFFF" key="textField-3" stretchType="NoStretch" positionType="FixRelativeToTop" isPrintRepeatedValues="true" isRemoveLineWhenBlank="false" isPrintInFirstWholeBand="false" isPrintWhenDetailOverflows="false"/> <box topBorder="None" topBorderColor="#000000" leftBorder="None" leftBorderColor="#000000" rightBorder="None" rightBorderColor="#000000" bottomBorder="None" bottomBorderColor="#000000"/> <textElement textAlignment="Left" verticalAlignment="Top" rotation="None" lineSpacing="Single"> <font fontName="Arial" pdfFontName="Helvetica" size="10" isBold="false" isItalic="false" isUnderline="false" isPdfEmbedded ="false" pdfEncoding ="Cp1252" isStrikeThrough="false" /> </textElement> <textFieldExpression class="java.lang.String"><![CDATA[$F{HITSEntityNameValue}]]></textFieldExpression> </textField> </band> </detail> <columnFooter> <band height="30" isSplitAllowed="true" > </band> </columnFooter> <pageFooter> <band height="50" isSplitAllowed="true" > </band> </pageFooter> <lastPageFooter> <band height="50" isSplitAllowed="true" > </band> </lastPageFooter> <summary> <band height="50" isSplitAllowed="true" > </band> </summary> </jasperReport> ---><--- I am using Jastperreports 1.2. Help is greatly appreciated. The Demos / samples / forum searches did not really help... Thanks, Michael 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