I'm trying to feed a simple .gif image from my GXT application to jasper so it generates an Excel report.
The problem I'm having is that after trying a multitude of options, I always get the "java.lang.NullPointerException" on the server-side of things.
I have the following code in my Jasper report:
<parameter name="logo" class="java.lang.String"/>
...
<image>
<reportElement uuid="2f9765a4-f1dc-4af4-9ddf-fae1c7a3d152" x="110" y="0" width="206" height="40"/>
<imageExpression><![CDATA[$P{logo}]]></imageExpression>
</image>
And the Java code:
FileResolver fileResolver = new FileResolver() {
@Override
public File resolveFile(String fileName) {
URI uri;
try {
uri = new URI(this.getClass().getResource(fileName).getPath());
return new File(uri.getPath());
} catch (URISyntaxException e) {
// TODO Auto-generated catch block
e.printStackTrace();
return null;
}
}
};
parameters.put("logo", fileResolver.resolveFile("logo.GIF"));
I've tried several solutions out there and had problems with all of them.
The logo.gif is placed in the .war folder of the compiled GWT application, the contents of which are archived as a .war and deployed on a Tomcat 7.0 server.
Hopefully someone with a bit more experience will help me out and let me know what I'm doing wrong.
The FileResolver object should be passed to Jasper like this:
parameters.put("REPORT_FILE_RESOLVER", fileResolver);
You shouldn't be calling fileResolver.resolveFile() yourself. The calling of FileResolver methods will be done by JasperReports itself. This question looks a lot like yours (maybe you've seen it) and it works by passing the FileResolver as a parameter.
You can find more info on FileResolver here. This page mentions that FileResolver is deprecated as of JasperReports 5.0.1. If you are using (or plan on using) 5.0.1+ you should try to use JasperResportsContext. For a usage example of JasperReportsContext you can refer to this question.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With