teenqueen
09-01-2009, 09:52 AM
I have a method:
public final void writeToTable(final Collection<Object> row) {
PdfPCell cell = null;
int col = 0;
for (Object value : row) {
if (value instanceof Collection) {
cell = new PdfPCell(
convertToParagraph((Collection<Object>) value));
} else if (value instanceof Number) {
cell = new PdfPCell(new Paragraph(
getFormattedNumber((Number) value)));
} else if(cell == null) {
cell = new PdfPCell(new Paragraph(removeSpecialText(value.toString())));
}
cell.setHorizontalAlignment(getJustification(col));
cell.setVerticalAlignment(Cell.ALIGN_CENTER);
pdfTable.addCell(cell);
col++;
}
}
I just added the code in red and now the code is producing duplicate information in different rows, but in reality there is different info. that goes into every row/column.
Please help me! and i wish i could just take out the cell == null but i can't because nullpointerexception is thrown if i have an empty column.
public final void writeToTable(final Collection<Object> row) {
PdfPCell cell = null;
int col = 0;
for (Object value : row) {
if (value instanceof Collection) {
cell = new PdfPCell(
convertToParagraph((Collection<Object>) value));
} else if (value instanceof Number) {
cell = new PdfPCell(new Paragraph(
getFormattedNumber((Number) value)));
} else if(cell == null) {
cell = new PdfPCell(new Paragraph(removeSpecialText(value.toString())));
}
cell.setHorizontalAlignment(getJustification(col));
cell.setVerticalAlignment(Cell.ALIGN_CENTER);
pdfTable.addCell(cell);
col++;
}
}
I just added the code in red and now the code is producing duplicate information in different rows, but in reality there is different info. that goes into every row/column.
Please help me! and i wish i could just take out the cell == null but i can't because nullpointerexception is thrown if i have an empty column.