Click to See Complete Forum and Search --> : duplicating values


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.

Khalid Ali
09-01-2009, 02:23 PM
instead you should post here where exactly is null pointer exception thrown from.
What you should do is, see which value is null and then change it to an empty string, that way you wont have to use if (cell==null)
You must have a logic to handle null values first