Java net.sf.jasperreports.engine.JRException:找不到字节数据

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/27174786/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-11 03:56:07  来源:igfitidea点击:

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

javaxmljasper-reports

提问by Marcin Erbel

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:

我正在尝试传递给 jasper 报告字符串位置的模板。所以我在模板和值中传递参数的键。当我的项目中有图像时,一切正常,但我想把它放在另一个地方。有没有办法从例如属性文件中读取参数?我不知道为什么这个解决方案不起作用:

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

采纳答案by Marcin Erbel

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>

回答by Cristian Arteaga

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.

显然它有效,因为我使用的是绝对路径(这不是一个好方法),然后我使用图像文件夹的参数更改了静态绝对路径。