I have this script to generate a barcode in ColdFusion:
<cfscript>
code128 = createobject("java","com.lowagie.text.pdf.Barcode128");
code128.setCodeType(code128.CODE128);
/* Set the code to generate */
code128.setCode("123")
color = createobject("java","java.awt.Color");
image = code128.createAwtImage(color.black, color.white);
bufferedImage = createObject("java", "java.awt.image.BufferedImage");
bufferedImageType = bufferedImage.TYPE_BYTE_GRAY;
bufferedImage = bufferedImage.init(image.getWidth(JavaCast("null", "")),image.getHeight(JavaCast("null", "")), bufferedImageType);
graphics2D = bufferedImage.createGraphics();
graphics2D.drawImage(image,0,0,JavaCast("null", ""));
barcodeImage = imageNew(bufferedImage);
</cfscript>
<!--- Output the code as an image --->
<cfimage action="writeToBrowser" source="#barcodeImage#" format="jpg" width="100" height="30">
I want to change code128.setCode("123") to something dynamic, ie code128.setCode("#someID#"). However, when I do that I receive a CF error:
Error message: Either there are no methods with the specified method name and argument types or the setCode method is overloaded with argument types that ColdFusion cannot decipher reliably. ColdFusion found 0 methods that match the provided arguments. If this is a Java object and you verified that the method exists, use the javacast function to reduce ambiguity.
Can someone help me with this one?
code128.setCode("123");but does not work withcode128.setCode("#someID#");? What is the value of #someID#? That error usually means exactly what it says - either a) you are trying to use a method that does not exist in the class at all OR b) you are passing in the wrong type of value, and need to usejavacastto convert it. For example, if that method expects a stringcode128.setCode( javacast("string", someID) );. Side note, not sure if it a typo, but you are missing a semi-colon on line three. - Leigh