Load image from byte[] error

0

I'm using JasperSoft Studio 6.8.0 and I've a struggling error:

I've a `logo` property of my Java class `EnvParameter`.

this property is a `byte[]`

I pass my Java class to Jasper Studio, so I try to load the image inside logo property as follow:

    net.sf.jasperreports.engine.util.JRImageLoader.loadAwtImageFromBytes($P{EnvParameter}.logo)

But I have this error:

> net.sf.jasperreports.engine.fill.JRExpressionEvalException: Error
> evaluating expression for source text:
> net.sf.jasperreports.engine.util.JRImageLoader.loadAwtImageFromBytes($P{EnvParameter}.logo)
>     at
> net.sf.jasperreports.engine.fill.JREvaluator.handleEvaluationException(JREvaluator.java:284)
>     at
> net.sf.jasperreports.compilers.GroovyEvaluator.handleEvaluationException(GroovyEvaluator.java:98)
>     at
> net.sf.jasperreports.engine.fill.JREvaluator.evaluate(JREvaluator.java:316)
>     at
> net.sf.jasperreports.engine.fill.JRCalculator.evaluate(JRCalculator.java:672)
>     at
> net.sf.jasperreports.engine.fill.JRCalculator.evaluate(JRCalculator.java:640)
>     at
> net.sf.jasperreports.engine.fill.JRFillElement.evaluateExpression(JRFillElement.java:1169)
>     at
> net.sf.jasperreports.engine.fill.JRFillImage.evaluateImage(JRFillImage.java:466)
>     at
> net.sf.jasperreports.engine.fill.JRFillImage.evaluate(JRFillImage.java:440)
>     at
> net.sf.jasperreports.engine.fill.JRFillElementContainer.evaluate(JRFillElementContainer.java:383)
>     at
> net.sf.jasperreports.engine.fill.JRFillBand.evaluate(JRFillBand.java:548)
>     at
> net.sf.jasperreports.engine.fill.JRVerticalFiller.fillTitle(JRVerticalFiller.java:323)
>     at
> net.sf.jasperreports.engine.fill.JRVerticalFiller.fillReport(JRVerticalFiller.java:150)
>     at
> net.sf.jasperreports.engine.fill.JRBaseFiller.fill(JRBaseFiller.java:615)
>     at
> net.sf.jasperreports.engine.fill.BaseReportFiller.fill(BaseReportFiller.java:414)
>     at
> net.sf.jasperreports.engine.fill.JRFillSubreport.fillSubreport(JRFillSubreport.java:814)
>     at
> net.sf.jasperreports.engine.fill.JRSubreportRunnable.run(JRSubreportRunnable.java:61)
>     at
> net.sf.jasperreports.engine.fill.AbstractThreadSubreportRunner.run(AbstractThreadSubreportRunner.java:221)
>     at
> java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
>     at
> java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
>     at java.lang.Thread.run(Thread.java:745) Caused by:
> groovy.lang.MissingMethodException: No signature of method: static
> net.sf.jasperreports.engine.util.JRImageLoader.loadAwtImageFromBytes()
> is applicable for argument types: ([B) values: [[-119, 80, 78, 71, 13,
> 10, 26, 10, 0, 0, 0, 13, 73, 72, 68, ...]] Possible solutions:
> loadAwtImageFromBytes([B)     at
> groovy.lang.MetaClassImpl.invokeStaticMissingMethod(MetaClassImpl.java:1518)
>     at
> groovy.lang.MetaClassImpl.invokeStaticMethod(MetaClassImpl.java:1504)
>     at
> org.codehaus.groovy.runtime.callsite.StaticMetaClassSite.call(StaticMetaClassSite.java:52)
>     at
> org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:47)
>     at
> org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:116)
>     at
> org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:128)
>     at
> rptVTitolo_1558437271760_434544.evaluate(calculator_rptVTitolo_1558437271760_434544:203)
>     at
> net.sf.jasperreports.engine.fill.JREvaluator.evaluate(JREvaluator.java:302)
>     ... 17 common frames omitted mag 21, 2019 1:17:36 PM
> org.apache.catalina.core.StandardWrapperValve invoke

Joe Taras's picture
Joined: Dec 3 2013 - 11:00am
Last seen: 2 weeks 22 hours ago

7 Answers:

0

I've done, I don't believe!!!

In Image element I've simple put ${EnvParameter}.getLogo() without call the function about load image.

 

Thank you for your support @C-Box

Joe Taras's picture
Joined: Dec 3 2013 - 11:00am
Last seen: 2 weeks 22 hours ago
1

Hi,

is the parameter really passed for the fill process and also not null?

perhaps it's better to use a (commonpublic getter instead direct access to that field "logo" in your parameter-class "Env-Parameter"? 

So that you could use $P{EnvParameter}.getLogo()  as ImageExpression?

Otherwise you could also change the report-language from Groovy to Java... just to see, if the compile process already has problems with your expression.

hth + regards

C-Box

 

 

C-Box's picture
1434
Joined: Jul 19 2006 - 5:58pm
Last seen: 21 hours 3 min ago
0

Dear, 

I've tried with getLogo() too but the error is the same.

Now I try to change language to Java (but it's very expensive because I must to change other groovy expressions in the report)

 

Joe Taras's picture
Joined: Dec 3 2013 - 11:00am
Last seen: 2 weeks 22 hours ago
0

Dear, I've tried to change my language from groovy to Java but I have a lot of errors as follow:

net.sf.jasperreports.engine.JRException: Errors were encountered when compiling report expressions class file:
1. Only a type can be imported. it.uncertainty.dmn.EnvParameter resolves to a package
import it.uncertainty.dmn.EnvParameter;

all for all occurencies of EnvParameter I used in my report

 

My head bursts!

Joe Taras's picture
Joined: Dec 3 2013 - 11:00am
Last seen: 2 weeks 22 hours ago
1

Hmm, seems that your import is wrong... try to use it as a package Import instead:

import it.uncertainty.dmn.EnvParameter.*;

hth

C-Box

 

C-Box's picture
1434
Joined: Jul 19 2006 - 5:58pm
Last seen: 21 hours 3 min ago
0

The same error with Java language selected ;(

Joe Taras's picture
Joined: Dec 3 2013 - 11:00am
Last seen: 2 weeks 22 hours ago
1

How is the package-Structure of our class " EnvParameter"?  Is it

a) it.uncertainty.dmn.EnvParameter   (so that the full resolved class name incl. package would be: it.uncertainty.dmn.EnvParameter.EnvParameter)

or just

b) it.uncertainty.dmn  (so that the full resolved class name incl. package would be: it.uncertainty.dmn.EnvParameter )

??? The compile error message would tell me, that your  given import resolved is directing to a package and not to the concrete class... !??!

regards

C-Box

C-Box's picture
1434
Joined: Jul 19 2006 - 5:58pm
Last seen: 21 hours 3 min ago
Feedback
randomness