Free Support Forum - aspose.com

NullPointerException when using Methods on Document Object

Hello,

I’m evaluating Aspose.Word. I’ve the problem that when I try to call Methods on the Document Object I get a NullPointer Exception.

Here’s my sample source:

public static void main(String[] args) {
Document doc;
try {
doc = new Document(“C:\Dokumente und Einstellungen\xgadjth\Desktop\test.doc”);
System.out.println("Seiten: " + doc.getPageCount());
PdfOptions pdfOpts = new PdfOptions();
pdfOpts.setTrueTypeFontsFolder(“C:\WINNT\Fonts”);
doc.saveToPdf(0, doc.getPageCount(), “C:\test.pdf”, pdfOpts);
doc.save(“C:\test.doc”);
} catch (Exception e) {
e.printStackTrace();
}
}

The Exception is thrown when calling the doc.getPageCount()!
I attatched the Document which I’am using for my test!

Any help is appreciated!

Hi

<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

Thanks for your inquiry. I tested your document on my side and converted it to PDF without any issues. Could you please provide me full stack trace of the exception? Maybe it will help me to understand what is going wrong on your side.

Best regards.

Hey,

if I take out the doc.getPages() call I can generate the PDF too.
The problem is that I can’t invoke a method on the Document class without getting a NullPointerException.

Here’s my Stacktrace:

java.lang.NullPointerException
at asposewobfuscated.jz.eV(Directory.java:87)
at asposewobfuscated.qx.a(TTFontFiler.java:788)
at asposewobfuscated.qx.iF(TTFontFiler.java:763)
at asposewobfuscated.qx.Vp(TTFontFiler.java:752)
at asposewobfuscated.qx.iz(TTFontFiler.java:321)
at asposewobfuscated.qx.C(TTFontFiler.java:117)
at asposewobfuscated.qx.B(TTFontFiler.java:42)
at asposewobfuscated.oa.hc(PalFont.java:24)
at com.aspose.words.xk.Ho(SpanPr.java:231)
at com.aspose.words.sl.rs(Span.java:730)
at com.aspose.words.sl.getWidth(Span.java:593)
at com.aspose.words.zy.JJ(LineBuilder.java:88)
at com.aspose.words.zy.JI(LineBuilder.java:30)
at com.aspose.words.bx.V(LinePart.java:281)
at com.aspose.words.k.c(ColumnBuilder.java:481)
at com.aspose.words.k.a(ColumnBuilder.java:163)
at com.aspose.words.k.a(ColumnBuilder.java:97)
at com.aspose.words.mz.a(PageBuilder.java:119)
at com.aspose.words.mz.a(PageBuilder.java:60)
at com.aspose.words.ajt.b(SectionReflower.java:40)
at com.aspose.words.io.nG(MainTextSectionLayout.java:757)
at com.aspose.words.qr.nG(StoryLayoutBase.java:88)
at com.aspose.words.mx.nG(PageLayoutModel.java:124)
at com.aspose.words.zh.a(LayoutDocument.java:33)
at com.aspose.words.Document.updatePageLayout(Document.java:1637)
at com.aspose.words.Document.IF(Document.java:1590)
at com.aspose.words.Document.getPageCount(Document.java:1618)
at de.thewes.aspose.words.test.Test.main(Test.java:17)

Hi

<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

Thanks for your request. Could you please try specifying TrueTypeFontDirectory before calling getPageCount. Try using the following code:

public static void main(String[] args) {

Document doc;

try {

PdfOptions pdfOpts = new PdfOptions();

pdfOpts.setTrueTypeFontsFolder("C:\\WINNT\\Fonts");

doc = new Document("C:\\Dokumente und Einstellungen\\xgadjth\\Desktop\\test.doc");

System.out.println("Seiten: " + doc.getPageCount());

doc.saveToPdf(0, doc.getPageCount(), "C:\\test.pdf", pdfOpts);

doc.save("C:\\test.doc");

} catch (Exception e) {

e.printStackTrace();

}

Please let me know if this helps.

Best regards.

Thx very much that did it!

Thanks for your help!