getting null when call acroform.getFields() using pdfbox
问题 I tried to get All the fields available in pdf form but I'm encountering a NullPointerException when calling acroform.getFields() using PDFBox. Sample: pdDoc = PDDocument.load(fileName); PDAcroForm form = pdDoc.getDocumentCatalog().getAcroForm(); if(form!=null) { List<PDField> field = form.getFields(); //here I am getting null pointer exception } 回答1: this is because your pdf if not contain any acroform 回答2: form is not null , but that doesn't mean it is not empty . Check this instead: if