Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Integrating Image in Jasper Reports using only Java

 
Russell Howse
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All,

I'm fairly new to Jasper Reports, and have been trying to create my reports using only Java code, basing it off of the noXMLDesign App that comes with the samples. One thing that isn't included, is how to add images to the report. I've added the following (see code), but when the report tries to compile, I get the following error:

"illegal start of expression"
value = (java.lang.String)(![CDATA["D:My DocumentsNetBeansProjectsSTAT 0.1buildImageslogo.jpg"]]); //$JR_EXPR_ID=12$"



Now, my question is, how do I properly set the expression for the image in Java? The expression that I wrote is what the iReport builder gave me when I added an image to the report, I just added the escape characters for quotations.


Appreciate any help.

Regards,

Russell

 
Martijn Verburg
author
Bartender
Posts: 3275
5
Eclipse IDE Java Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Russel and welcome to Javaranch!

Strange that the escapes for the backslash aren't working. Can you quickly try forward slash to see if that gets removed by the parser as well?
 
Russell Howse
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for the reply.

That's actually a bit of a mistake on my part. I've tried quite a few variations, and that error message didn't match the code I gave in my previous post. I added two escape backslashes in the directory to get two in the expression itself, as shown in the sample I ran through the designer. This is what it shows.

<imageExpression class="java.lang.String"><![CDATA["D:\\My Documents\\NetBeansProjects\\STAT 0.1\\build\\Images\\logo.jpg"]]></imageExpression>

My string value:

D:\My Documents\NetBeansProjects\STAT 0.1\StudentReport_1268229604078_194850.java:241: illegal start of expression
value = (java.lang.String)(![CDATA["D:\\My Documents\\NetBeansProjects\\STAT 0.1\\build\\Images\\logo.jpg"]]); //$JR_EXPR_ID=20$

With an arrow pointing to the first opening square bracket.

I've also tried
and because of Martin's post, tried this as well

However, I got the same error both times.
 
Martijn Verburg
author
Bartender
Posts: 3275
5
Eclipse IDE Java Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You might have to do some experimentation at this stage just to see what the parser will accept. For example try giving it a (admittedly false) path with no slashes in it at all, is that a legal expression?
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic