Код: Выделить всё
...
private Document _pdf;
public Report()
{
_pdf = new Document();
}
public string GenerateReport(string reportType) {
try {
var fs = new FileStream("C:\\myfile.pdf", FileMode.Create);
_pdfWriter = PdfWriter.GetInstance(_pdf, fs);
...
Object reference not set to an instance of an object.
at iTextSharp.text.pdf.PdfWriter.GetInstance(Document document, Stream os)
at Report.GenerateReport(String reportType)
< /code>
Почему, по вашему мнению,
я получаю эту ошибку? FileStream был создан, и _pdf установлен в конструкторе. P> Проблема в том, что _PDF является нулевой. Я не уверен, почему он нулевой, как установлен в конструкторе. Я могу решить эту проблему, выполняя: < /p>
if (_pdf == null) {
_pdf = new Document();
}
_pdfWriter = PdfWriter.GetInstance(_pdf, fs);
< /code>
Я все еще хотел бы знать, что я делаю не так ... < /p>
Подробнее здесь: https://stackoverflow.com/questions/167 ... ject-error