I am having problems creating an updating a barcode object within a class.
My barcode class is created as follows: public void addBarcode39(String bartype, String barcode, String minbarwidth, String barmultiply, String barfontbase, String barfontttf, String barencoding, String barembedded, String barfontsize, String baseline, String barheight, String textalign, String checksum,String startstop, String extended, String barcolourR, String barcolourG, String barcolourB, String textcolourR, String textcolourG, String textcolourB, String barunder, String barposX, String barposY) { // Create class instance iPDFBarcode39 bar39 = new iPDFBarcode39(bartype.trim(), barcode.trim(), minbarwidth.trim(), barmultiply.trim(), barfontbase.trim(), barfontttf.trim(), barencoding.trim(), barembedded.trim(), barfontsize.trim(), baseline.trim(), barheight.trim(), textalign.trim(), checksum.trim(), startstop.trim(), extended.trim(), barcolourR.trim(), barcolourG.trim(), barcolourB.trim(), textcolourR.trim(), textcolourG.trim(), textcolourB.trim(), barunder.trim(), barposX.trim(), barposY.trim()); // Add barcode39 array element vBar.add(Barcode39); vBar.add(bar39); vBarcode.add(vBar); } // Set bar code public void setBarcode(Barcode39 barcode, String code) { // Set bar code barcode.setCode(code); } The source for the iPDFBarcode39 class is shown below: /*************************************************************************************************** * Author.........: Paul Manners * Creation Date..: * Copyright **************************************************************************************************/ import org.apache.commons.lang.StringUtils; import com.lowagie.text.Element; import com.lowagie.text.ExceptionConverter; import com.lowagie.text.Font; import com.lowagie.text.FontFactory; import java.awt.Color; import com.lowagie.text.pdf.Barcode; import com.lowagie.text.pdf.Barcode39; import com.lowagie.text.pdf.BaseFont; public class iPDFBarcode39 { private String pbartype = ""; private String pbarcode = ""; private String pminbarwidth = ""; private String pbarmultiply = ""; private String pbarfontbase = ""; private String pbarfontttf = ""; private String pbarencoding = ""; private String pbarembedded = ""; private String pbarfontsize = ""; private String pbaseline = ""; private String pbarheight = ""; private String ptextalign = ""; private String pchecksum = ""; private String pstartstop = ""; private String pextended = ""; private String pbarcolourR = ""; private String pbarcolourG = ""; private String pbarcolourB = ""; private String ptextcolourR = ""; private String ptextcolourG = ""; private String ptextcolourB = ""; private String pbarunder = ""; private String pbarposX = ""; private String pbarposY = ""; private float fminbarwidth = 0; private float fbarmultiply = 0; private float fbarfontsize = 0; private float fbaseline = 0; private float fbarheight = 0; private float fbarcolourR = 0; private float fbarcolourG = 0; private float fbarcolourB = 0; private float ftextcolourR = 0; private float ftextcolourG = 0; private float ftextcolourB = 0; private float fbarposX = 0; private float fbarposY = 0; private boolean notblank; private boolean usebasefont; private boolean barfontembedded = false; private boolean barchecksum = false; private boolean barstartstop = false; private boolean barextended = false; private Font stdbarfont; private Font ttfbarfont; private BaseFont stdbasebar; private BaseFont ttfbasebar; private Color ipdfbarcolor; private Color ipdftextcolor; public String barcodetype; public Barcode39 ipdfbar39; // Barcode constants public static final String BarcodeType = "Barcode39"; // Boolean constants public static final String Yes = "Y"; public static final String No = "N"; // Alignment constants public static final String Left = "LEFT"; public static final String Middle = "MIDDLE"; public static final String Right = "RIGHT"; iPDFBarcode39(String bartype, String barcode, String minbarwidth, String barmultiply, String barfontbase, String barfontttf, String barencoding, String barembedded, String barfontsize, String baseline, String barheight, String textalign, String checksum, String startstop, String extended, String barcolourR, String barcolourG, String barcolourB, String textcolourR, String textcolourG, String textcolourB, String barunder, String barposX, String barposY) { try { // Setup instance variables this.barcodetype = BarcodeType; this.pbartype = bartype; this.pbarcode = barcode; this.pminbarwidth = minbarwidth; this.pbarmultiply = barmultiply; this.pbarfontbase = barfontbase; this.pbarfontttf = barfontttf; this.pbarencoding = barencoding; this.pbarembedded = barembedded; this.pbarfontsize = barfontsize; this.pbaseline = baseline; this.pbarheight = barheight; this.ptextalign = textalign; this.pchecksum = checksum; this.pstartstop = startstop; this.pextended = extended; this.pbarcolourR = barcolourR; this.pbarcolourG = barcolourG; this.pbarcolourB = barcolourB; this.ptextcolourR = textcolourR; this.ptextcolourG = textcolourG; this.ptextcolourB = textcolourB; this.pbarunder = barunder; this.pbarposX = barposX; this.pbarposY = barposY; this.fbarposX = Float.valueOf(barposX.trim()).floatValue(); this.fbarposY = Float.valueOf(barposY.trim()).floatValue(); // Font embedded if (barembedded.trim().equals(Yes)) { this.barfontembedded = true; } else { this.barfontembedded = false; } // Bar checksum if (checksum.trim().equals(Yes)) { this.barchecksum = true; } else { this.barchecksum = false; } // Bar start/stop text if (startstop.trim().equals(Yes)) { this.barstartstop = true; } else { this.barstartstop = false; } // Bar extended flag if (extended.trim().equals(Yes)) { this.barextended = true; } else { this.barextended = false; } // Check if barcode provided notblank = StringUtils.isNotBlank(this.pbarcode.trim()); // Barcode provided if (notblank == true) { setBarcode(this.ipdfbar39, barcode); // Set bar colour setBarColour(barcolourR, barcolourG, barcolourB); // Set bar text colour setTextColour(textcolourR, textcolourG, textcolourB); // Set minimum bar width setMinBarWidth(minbarwidth); // Set font setFont(barfontbase, barfontttf, barencoding, this.barfontembedded, barfontsize); // Set bar baseline setBarBaseline(baseline); // Set bar multiplier for wide bars setBarMultiply(barmultiply); // Set bar height setBarHeight(barheight); // Set text alignment setTextAlign(textalign); // Set checksum setChecksum(this.barchecksum); // Set start/stop text setStartStop(this.barstartstop); // Set bar extended flag setBarExtended(this.barextended); } } catch(Exception e) { throw new ExceptionConverter(e); } } iPDFBarcode39() { } // Set bar code public void setBarcode(Barcode39 barcode, String code) { // Set bar code barcode.setCode(code); } // Set minimum bar width public void setMinBarWidth(String minbarwidth) { if (minbarwidth.trim() != "") { // Convert to float this.fminbarwidth = Float.valueOf(minbarwidth.trim()).floatValue(); // Set minimum bar width this.ipdfbar39.setX(this.fminbarwidth); } } // Set bar multiplier for wide bars public void setBarMultiply(String barmultiply) { if (barmultiply.trim() != "") { // Convert to float this.fbarmultiply = Float.valueOf(barmultiply.trim()).floatValue(); // Set bar multiplier this.ipdfbar39.setN(this.fbarmultiply); } } // Set bar baseline public void setBarBaseline(String baseline) { if (baseline.trim() != "") { // Convert to float this.fbaseline = Float.valueOf(baseline.trim()).floatValue(); // Set bar multiplier this.ipdfbar39.setBaseline(this.fbaseline); } } // Set bar height public void setBarHeight(String barheight) { if (barheight.trim() != "") { // Convert to float this.fbarheight = Float.valueOf(barheight.trim()).floatValue(); // Set bar multiplier this.ipdfbar39.setBarHeight(this.fbarheight); } } // Set bar checksum public void setChecksum(boolean checksum) { // Set checksum this.ipdfbar39.setChecksumText(checksum); } // Set bar Start/Stop public void setStartStop(boolean startstop) { // Set checksum this.ipdfbar39.setStartStopText(startstop); } // Set bar Extended public void setBarExtended(boolean extended) { // Set extended flag this.ipdfbar39.setExtended(extended); } // Set bar text alignment public void setTextAlign(String textalign) { // Left if (textalign.trim().equals(Left)) { this.ipdfbar39.setTextAlignment(Element.ALIGN_LEFT); } // Middle if (textalign.trim().equals(Middle)) { this.ipdfbar39.setTextAlignment(Element.ALIGN_CENTER); } // Right if (textalign.trim().equals(Right)) { this.ipdfbar39.setTextAlignment(Element.ALIGN_RIGHT); } } // Set bar colour public void setBarColour(String barcolourR, String barcolourG, String barcolourB) { if ((barcolourR.trim() != "") && (barcolourG.trim() != "") && (barcolourB.trim() != "")) { // Convert to float this.fbarcolourR = Float.valueOf(barcolourR.trim()).floatValue(); this.fbarcolourG = Float.valueOf(barcolourG.trim()).floatValue(); this.fbarcolourB = Float.valueOf(barcolourB.trim()).floatValue(); // Create colour object this.ipdfbarcolor = new Color(fbarcolourR,fbarcolourG,fbarcolourB); } else { // Create colour object this.ipdfbarcolor = null; } } // Set bar text colour public void setTextColour(String textcolourR, String textcolourG, String textcolourB) { if ((textcolourR.trim() != "") && (textcolourG.trim() != "") && (textcolourB.trim() != "")) { // Convert to float this.ftextcolourR = Float.valueOf(textcolourR.trim()).floatValue(); this.ftextcolourG = Float.valueOf(textcolourG.trim()).floatValue(); this.ftextcolourB = Float.valueOf(textcolourB.trim()).floatValue(); // Create colour object this.ipdftextcolor = new Color(ftextcolourR,ftextcolourG,ftextcolourB); } else { // Create colour object this.ipdftextcolor = null; } } // Set bar font public void setFont(String barfontbase, String barfontttf, String barencoding, boolean barembedded, String barfontsize) { try { if (barfontbase.trim() != "" || barfontttf.trim() != "") { // Font size this.fbarfontsize = Float.valueOf(barfontsize.trim()).floatValue(); // Check if base font required usebasefont = StringUtils.isNotBlank(barfontbase.trim()); // Base font required if (usebasefont == true) { // Standard font this.stdbarfont = FontFactory.getFont(barfontbase, barfontsize); this.stdbasebar = getFontBase(this.stdbarfont); } else { this.ttfbasebar = BaseFont.createFont(barfontttf, barencoding, barembedded); } } } catch(Exception e) { throw new ExceptionConverter(e); } } // Retrieve base font from font object BaseFont getFontBase(Font font) { return font.getBaseFont(); } public String getBartype() { return pbartype; } public String getBarcode() { return pbarcode; } public String getMinbarwidth() { return pminbarwidth; } public String getBarmultiply() { return pbarmultiply; } public String getBarfontbase() { return pbarfontbase; } public String getBarfontttf() { return pbarfontttf; } public String getBarfontsize() { return pbarfontsize; } public String getBaseline() { return pbaseline; } public String getBarheight() { return pbarheight; } public String getTextalign() { return ptextalign; } public String getChecksum() { return pchecksum; } public String getStartstop() { return pstartstop; } public String getExtended() { return pextended; } public String getBarcolourR() { return pbarcolourR; } public String getBarcolourG() { return pbarcolourG; } public String getBarcolourB() { return pbarcolourB; } public String getTextcolourR() { return ptextcolourR; } public String getTextcolourG() { return ptextcolourG; } public String getTextcolourB() { return ptextcolourB; } public String getBarunder() { return pbarunder; } public String getBarposX() { return pbarposX; } public String getBarposY() { return pbarposY; } } The problem occurs during the setBarcode(this.ipdfbar39, barcode); function... When the setCode procedure is run... // Set bar code public void setBarcode(Barcode39 barcode, String code) { // Set bar code barcode.setCode(code); } ..I get the following exception thrown: ************Beginning of data************** java.lang.NullPointerException at iPDFBarcode39.setBarcode(iPDFBarcode39.java:205) at iPDFBarcode39.<init>(iPDFBarcode39.java:163) at RPGiPDF.addBarcode39(RPGiPDF.java:547) ************End of Data******************** The barcode object is shown below: EVAL barcode barcode = null barcode.BARS = ****** barcode.CHARS = ****** barcode.EXTENDED = ****** I was under the impression that when a new class was constructed, that all variables within that class are also constructed and that these variables could then be used. I'm not sure if this is an iText issue or my java. Any assistance on this issue would be most appreciated. Thanks Paul -- View this message in context: http://www.nabble.com/NullPointerException-during-creation-update-of-barcode-object-tp24031329p24031329.html Sent from the iText - General mailing list archive at Nabble.com. ------------------------------------------------------------------------------ Crystal Reports - New Free Runtime and 30 Day Trial Check out the new simplified licensing option that enables unlimited royalty-free distribution of the report engine for externally facing server and web deployment. http://p.sf.net/sfu/businessobjects _______________________________________________ iText-questions mailing list iText-questions@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/itext-questions Buy the iText book: http://www.1t3xt.com/docs/book.php Check the site with examples before you ask questions: http://www.1t3xt.info/examples/ You can also search the keywords list: http://1t3xt.info/tutorials/keywords/