我正在尝试创建一个表数组(2 个表)。 我的程序在最后一行停止并出现空指针异常。知道为什么吗?
com.lowagie.text.pdf.PdfPTable[] table = new com.lowagie.text.pdf.PdfPTable[1];
// the cell object
com.lowagie.text.pdf.PdfPCell cell;
// header
cell = new PdfPCell(new Phrase(wdComponentAPI.getMessage("Ordernr")));
cell.setColspan(1);
cell.setBackgroundColor(Color.LIGHT_GRAY);
cell.setHorizontalAlignment(Element.ALIGN_CENTER);
table[0].addCell(cell);
最佳答案
数组不是随着对象的创建而创建的
PdfPTable [] tables = new PdfPTable[1];
tables[0].doStuff() // null pointer
在数组中创建对象
PdfPTable [] tables = new PdfPTable[1];
tables[0] = new PdfPTable();
tables[0].doStuff() // works good!
关于java - PdfPTables[] 数组填充时出现空指针异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23286839/