Free Support Forum -

Document.getPageCount throws java.lang.NullPointerException


When we call Document.getPageCount() just after loading certain documents we’re getting a java.lang.NullPointerException. I will attach an example document here.

nullpointerexample.docx (13.7 KB)

We’re using v21.4 and I can reproduce this on Mac and on Linux.

openjdk 11.0.11 2021-04-20
OpenJDK Runtime Environment AdoptOpenJDK-11.0.11+9 (build 11.0.11+9)
OpenJDK 64-Bit Server VM AdoptOpenJDK-11.0.11+9 (build 11.0.11+9, mixed mode)

Stack trace:

Caused by: Error occurred determining page count
    at (
    at (
    at (
    at (
    at org.codehaus.mojo.exec.ExecJavaMojo$ (
    at (
Caused by: java.lang.NullPointerException
    at com.aspose.words.zzZX.zzh5 (Unknown Source)
    at com.aspose.words.zzZDK.zzW (Unknown Source)
    at com.aspose.words.zzZDK.zzUb (Unknown Source)
    at com.aspose.words.zzZDD.zzZ (Unknown Source)
    at com.aspose.words.zzZDD.zzN (Unknown Source)
    at com.aspose.words.zzZDO.zzF (Unknown Source)
    at com.aspose.words.zzZDM.zzz (Unknown Source)
    at com.aspose.words.zzZDM.zzW (Unknown Source)
    at com.aspose.words.zzZDM.zzX (Unknown Source)
    at com.aspose.words.zzVG.zzZ (Unknown Source)
    at com.aspose.words.zzVG.zzZ (Unknown Source)
    at com.aspose.words.zzYOL.zzYpI (Unknown Source)
    at com.aspose.words.zzYOL.zzY (Unknown Source)
    at com.aspose.words.zzYOL.zzZ (Unknown Source)
    at com.aspose.words.zzWY.zz8c (Unknown Source)
    at com.aspose.words.zzWY.zzW (Unknown Source)
    at com.aspose.words.zzWY.zzX (Unknown Source)
    at com.aspose.words.zzYYB.zzB (Unknown Source)
    at com.aspose.words.zzYYB.zzC (Unknown Source)
    at com.aspose.words.zzYYB.zzYFC (Unknown Source)
    at com.aspose.words.zzYYB.zzL (Unknown Source)
    at com.aspose.words.zzYXH.zzJ (Unknown Source)
    at com.aspose.words.zzYMM.zza (Unknown Source)
    at com.aspose.words.zz3P.zzJ (Unknown Source)
    at com.aspose.words.zz3Q.zzZxv (Unknown Source)
    at com.aspose.words.zzYYF.zzYFY (Unknown Source)
    at com.aspose.words.Document.updatePageLayout (Unknown Source)
    at com.aspose.words.Document.zzWa (Unknown Source)
    at com.aspose.words.Document.getPageCount (Unknown Source)
    at (
    at (
    at (
    at (
    at org.codehaus.mojo.exec.ExecJavaMojo$ (
    at (


We have tested the scenario and managed to reproduce the same issue at our side. For the sake of correction, we have logged this problem in our issue tracking system as WORDSJAVA-2581. You will be notified via this forum thread once this issue is resolved.

We apologize for your inconvenience.

1 Like