This is a strange error that I have not been able to figure out. I'm
hoping that maybe some fresh eyes will quickly see my error and point it
out. I have been looking through the book as well as the mailing lists
and just general Google searches and so far I'm not finding anything
(maybe I just haven't hit the right combination of key words, but
nothing pertinent is showing up).
I'm creating a document, creating several tables (PdfPTables) and adding
them to the document as they get created. Of course I'm adding cells
(PdfPCells) to each of the tables as I create them.
At the point this error is occurring the document has had a header and
footer added and has been opened. I have also created an entire table
and added it to the document. This error is happening as I try to add
column headings to the detail table that will make up the bulk of this
document. I have already added a number of column headings to the table
already using the same process I'm using when the error is thrown.
The error is a null pointer exception, here is the first part of the
stack trace.
java.lang.NullPointerException
at com.lowagie.text.pdf.ColumnText.findLimitsPoint(Unknown
Source)
at com.lowagie.text.pdf.ColumnText.findLimitsOneLine(Unknown
Source)
at com.lowagie.text.pdf.ColumnText.findLimitsTwoLines(Unknown
Source)
at com.lowagie.text.pdf.ColumnText.go(Unknown Source)
at com.lowagie.text.pdf.PdfPRow.calculateHeights(Unknown Source)
at com.lowagie.text.pdf.PdfPRow.getMaxHeights(Unknown Source)
at com.lowagie.text.pdf.PdfPTable.addCell(Unknown Source)
I don't want to include the code to the entire class here because it's
just to long, but I'll try to add the pertinent bits. Here is my table
definition.
detailTable = new PdfPTable(SuppConConstants.INT_19);
detailTable.setTotalWidth(totalWidth); // 200
detailTable.setWidthPercentage(widthsPercent); // 100
detailTable.setWidths(detailColWidths);
detailTable.setSpacingAfter(15f);
detailTable.setHeaderRows(SuppConConstants.INT_1);
As you can see the table as a large number of columns (it is landscape).
Here are the values of the width and column widths variables.
private float totalWidth = 200;private float widthsPercent = 100;
float[] detailColWidths = { 14, 8, 7, 2, 8, 2, 7, 2, 7, 2, 7, 2, 7, 2,
6, 2, 6, 2, 7 };
These are the cell and table declarations.
private PdfPCell cell = null;
private PdfPTable detailTable = null;
Here are the couple of cells prior to the problem area and the add cell
that is failing.
This cell creation works and adds to the table.
cell = PdfDocumentUtility.newCell(langHelper.getLabel("end_serial"),
cellBoldFontNine);
cell.setBackgroundColor(cellBgColor);
cell.setBorder(Rectangle.NO_BORDER);
cell.setHorizontalAlignment(Rectangle.ALIGN_LEFT);
cell.setVerticalAlignment(Rectangle.ALIGN_MIDDLE);
cell.setUseBorderPadding(true);
detailTable.addCell(cell);
This cell creation works and adds to the table.
cell = PdfDocumentUtility.newCell(SuppConConstants.SPACE_CHAR,
cellBoldFontNine);
cell.setBackgroundColor(cellBgColor);
cell.setBorder(Rectangle.NO_BORDER);
cell.setHorizontalAlignment(Rectangle.ALIGN_LEFT);
cell.setVerticalAlignment(Rectangle.ALIGN_MIDDLE);
cell.setUseBorderPadding(true);
detailTable.addCell(cell);
This cell creation and add is the one that throws the error.
The logger.log lines are temporary lines I've added while trying to
solve this that just make entries into the application log file. I get
log entries for the statement immediately below (that is essentially
looking up a language label and returning the text value to print for
the column heading - it comes back with the expected value). The
cellBoldFontNine is a centrally available font, 9pt, that is bolded. I
do NOT get log entries indicating that the cell or the table are null.
logger.log(Level.INFO, "langHelper master label: " +
langHelper.getLabel("master"));
cell = PdfDocumentUtility.newCell(langHelper.getLabel("master"),
cellBoldFontNine);
cell.setBackgroundColor(cellBgColor);
cell.setBorder(Rectangle.NO_BORDER);
cell.setHorizontalAlignment(Rectangle.ALIGN_LEFT);
cell.setVerticalAlignment(Rectangle.ALIGN_MIDDLE);
cell.setUseBorderPadding(true);
if (cell == null) {
logger.log(Level.INFO, "cell is null");
}
if (detailTable == null) {
logger.log(Level.INFO, "detailTable is null");
}
detailTable.addCell(cell);
Does anyone see what the problem is? This has worked for the first
table in this document and is basically the same process we use to
generate a large number of PDF's within our application. It's probably
something simple, but it is eluding me. Oh, one more thing, here is the
code for the newCell method in our document utility class.
public static PdfPCell newCell(String text, Font font) {
PdfPCell pdfCell = null;
PdfPCell cell = null;
if (text == null) {
// create a blank cell
cell = new PdfPCell(new Phrase(" ", font));
}
else {
cell = new PdfPCell(new Phrase(text, font));
}
pdfCell = new PdfPCell(cell);
return pdfCell;
}
Thanks
steve
The contents of this e-mail are intended for the named addressee only. It
contains information that may be confidential. Unless you are the named
addressee or an authorized designee, you may not copy or use it, or disclose it
to anyone else. If you received it in error please notify us immediately and
then destroy it.
------------------------------------------------------------------------------
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/