3

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.

enrybo
  • 1,787
  • 1
  • 12
  • 20
Eugen
  • 1,537
  • 7
  • 29
  • 57
  • Is the `URISyntaxException` being thrown? – enrybo Mar 19 '13 at 11:32
  • When you say the gif is placed in compiled GWT application's war file, where its placed exactly? In client module (which has all the generated JS files) or server modules (where servlet classes are present)? Please tell the path of GIF – sanbhat Mar 27 '13 at 09:40

1 Answers1

2

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.

Community
  • 1
  • 1
enrybo
  • 1,787
  • 1
  • 12
  • 20
  • Thanks for your answer, however the logo does not appear. is there anything I'm missing in the Jasper code? – Eugen Mar 19 '13 at 12:23
  • Are you using `<![CDATA["logo.gif"]]>`? (In which case you don't need ``) – enrybo Mar 19 '13 at 12:47
  • Yeap. I'm still getting a null pointer exception at uri = new URI(this.getClass().getResource(fileName).getPath()); – Eugen Mar 19 '13 at 13:03
  • 2
    I would try to debug that line by either putting a break point there in your IDE or by printing out the String `getClass().getResource(fileName).getPath()`. That needs to be an absolute path to your file. – enrybo Mar 19 '13 at 14:35