简体   繁体   中英

net.sf.jasperreports.engine.JRException: Byte data not found

I'm trying to pass to template of a jasper reports string location. So I'm passing key of a parameter inside template and value. Everything was working when I had image inside my project, but I would like to have it on the other place. Is there any way to read parameters from, for instance properties file? I don't know why this sollution is not working:

My image:

<parameter name="imagesDir" class="java.lang.String" isForPrompting="false"/>

...

<image isLazy="true">
    <reportElement key="image-1" style="PHLabel" x="0" y="0" width="160" height="33"/>
    <imageExpression class="java.lang.String"><![CDATA["$P{imagesDir}"+"logo.bmp"]]></imageExpression>
</image>

error:

Error during exporting report statement_account_10 to PDF.
net.sf.jasperreports.engine.JRException: Byte data not found at : 
((java.lang.String)parameter_imagesDir.getValue())logo.bmp

Ok i found it... Should be:

<image isLazy="true">
    <reportElement key="image-1" style="PHLabel" x="0" y="0" width="160" height="33"/>
    <imageExpression class="java.lang.String"><![CDATA[$P{imagesDir}+"logo.bmp"]]></imageExpression>
</image>

I had this issue and in my case the problem was the path of the image.

Initially I had something like:

<imageExpression><![CDATA["logo.bmp"]]></imageExpression>

Then I replaced it by:

<imageExpression><![CDATA["/home/reports/logo.bmp"]]></imageExpression>

Obviously it worked because I was using the absolute path (Which is not a good approach), Then I changed the static absolute path with a parameter for the images folder.

I don't know if my case is exactly the same as @Cristian Arteaga's, but his solution inspired the one that worked for me.

In my case, this happened with a report that was created in Jaspersoft Studio 6.x, then opened back in iReport 4.5.1 (as I needed it to be compatible with that version of the library and, after many unsuccessful attempts, this was the only way for me to accomplish so), then being included as a subreport in another main report (when runing it as a stand-alone report it didn't happen).

All in all, it was as simply as deleting the image that was causing the problem, then importing it again. After prompting for the file and importing it, in properties, instead of showing only the name of the file, it would show also the full path. Compiled and tried the main report and no problems anymore.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM