Я пытаюсь использовать определенные функции, для которых требуется jar-файл ooxml-schemas, и даже после импорта библиотеки poi-ooxml и библиотеки ooxml-schemas через Maven я все равно получаю исключение NullPointerException в 13-й строке. Я использую IntelliJ IDEA 2017.
import java.io.*;
import java.math.BigInteger;
import org.apache.poi.util.Units;
import org.apache.poi.wp.usermodel.HeaderFooterType;
import org.apache.poi.xwpf.usermodel.*;
import org.openxmlformats.schemas.wordprocessingml.x2006.main.*;
public class ASM {
public static void main(String[] args) throws Exception {
XWPFDocument document = new XWPFDocument();
FileOutputStream out = new FileOutputStream(new File("AASM.docx"));
CTSectPr sectPr = document.getDocument().getBody().getSectPr();
CTPageSz pageSz = sectPr.getPgSz();
double pageWidth = pageSz.getW().doubleValue();
CTPageMar pageMar = sectPr.getPgMar();
double pageMarginLeft = pageMar.getLeft().doubleValue();
double pageMarginRight = pageMar.getRight().doubleValue();
double effectivePageWidth = pageWidth - pageMarginLeft - pageMarginRight;
//Header
XWPFHeader header = document.createHeader(HeaderFooterType.DEFAULT);
XWPFTable headerTable = header.createTable(1, 3);
CTTblWidth width = headerTable.getCTTbl().addNewTblPr().addNewTblW();
width.setType(STTblWidth.DXA);
width.setW(new BigInteger(effectivePageWidth + ""));
XWPFTableRow headerTableRowOne = headerTable.getRow(0);
//Cell 0
XWPFTableCell companyCell = headerTableRowOne.getCell(0);
XWPFParagraph companyParagraph = companyCell.addParagraph();
XWPFRun companyRun = companyParagraph.createRun();
InputStream companyImageInputStream = new BufferedInputStream(new FileInputStream("20opy.png"));
companyRun.addPicture(companyImageInputStream, Document.PICTURE_TYPE_PNG, "20opy.png", Units.toEMU(125), Units.toEMU(19));
//Main Document
XWPFParagraph paragraph = document.createParagraph();
XWPFRun run = paragraph.createRun();
run.setText("Hello world");
run.addPicture(companyImageInputStream, Document.PICTURE_TYPE_PNG, "20opy.png", Units.toEMU(125), Units.toEMU(19));
document.write(out);
out.close();
System.out.println("Finished");
}
}
Подробнее здесь: https://stackoverflow.com/questions/547 ... rexception