I have had situations like this happen to me.. What I did, is pass the
information from one function to another..
onEndPage(writer, document, data);
public void onEndPage(PdfWriter writer, Document document, DataObject
data)
Glen Hamel
Lead Programmer / Technician
Auric Networks Canada, Inc.
570 Orwell Street, Unit 1
Mississauga, Ontario
L5A 3V7
Phone 905.361.7621
Fax 905.274.3912
http://www.auricnet.ca
From:
"Tim Tönnsen" <[EMAIL PROTECTED]>
To:
itext-questions@lists.sourceforge.net
Date:
06/03/2008 10:51 AM
Subject:
[iText-questions] NullPointerException in onEndPage
Hi Everybody,
in the moment I am writing an application for a Customer. One
functionality is the option to generate a pdf-file. To do this, I wrote a
Controller which extends the PdfPageEventHelper. the Controller has a
print(DataObject toPrint) method. These PrintMethod prints the Data's
given as the parameter "toPrint", but first of all the toPrint Object is
stored in a global variable. Everything worked fine until I overrids the
onPageEnd Method, to generate a Header. The problem is that the global
Variable holding the data to be printed is null, althought is was set by
the call of the print method. Unfortunately, I am not allowed to send the
complete code, but I added a bit pseudoCode to ilustrate the Problem a bit
Better:
public class PdfController extends PdfPageEventHelper
{
private DataObject data;
public void print(DataObject toPrint)
{
this.data = toPrint;
Document document = new Document(PageSize.A4, 50, 50, 100, 70);
PdfWriter writer = PdfWriter.getInstance(document, new
FileOutputStream("HelloWorld.pdf"));
document.open();
//do some PDF-Generation Stuff, depending on which kind of data is
in "data"
document.newPage();
//do some PDF-Generation Stuff, depending on which kind of data is
in "data"
document.close();
}
public void onEndPage(PdfWriter writer, Document document)
{
//setup the header
PdfPTable table = new PdfPTable(1);
table.addCell((String)data.getFirstHeaderElement());
head.addCell(table);
//do some more stuff..
}
}
In the Line table.addCell((String)data.getFirstHeaderElement()); in the
onEndPageMethod I get an NullPointerException, during debugging I saw,
that "data" is set directly before the call of "document.newPage();" but
in the "onPageEnd"-Method it is null. Can you tell me what the Problem is,
and how to solve it? Thanks a million
armerIrrer
--
-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2008.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
_______________________________________________
iText-questions mailing list
iText-questions@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/itext-questions
Do you like iText?
Buy the iText book: http://www.1t3xt.com/docs/book.php
Or leave a tip: https://tipit.to/itexttipjar