• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Bear Bibeault
  • Junilu Lacar
  • Martin Vashko
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Knute Snortum
Saloon Keepers:
  • Ron McLeod
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Scott Selikoff
  • salvin francis
  • Piet Souris

Adding Header/Footer to Word Document, created using HWPF/XWPF.

 
Ranch Hand
Posts: 952
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I have written code to create a word document using Apache XWPF. I need to add a header and footer to this word doc.
Following is the code:



================================================================================

When I run the above piece of code, I am getting the following runtime exception:

Caught an: java.lang.NullPointerException
Message: null
Stacktrace follows:.....
java.lang.NullPointerException
at org.apache.poi.xwpf.model.XWPFHeaderFooterPolicy.<init>(XWPFHeaderFooterPolicy.java:106)
at org.apache.poi.xwpf.model.XWPFHeaderFooterPolicy.<init>(XWPFHeaderFooterPolicy.java:92)
at HeaderFooterExample.createDocument(HeaderFooterExample.java:56)
at HeaderFooterExample.main(HeaderFooterExample.java:199)

=============================================================================

I am not sure what is wrong with the above code.
Any help on how to create a word document with header/footer using HWPF/XWPF will be appreciated.

Thanks..





 
Bartender
Posts: 1952
7
Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Given the stacktrace, I would assume the XWPFDocument is not in a valid state for ceating an XWPFHeaderFooterPolicy.
Maybe there's more information on pre-conditions in the POI API or user documentation?
 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I faced this issue and the solution is We have to use 3.10 final poi jar. 3.9 having this problem. Please remove jars of previous version and add jars of 3.10 final version in which this bug is fixed. jars requires are 1. poi-3.10-FINAL.jar 2. poi-ooxml-3.10-FINAL.jar 3. poi-ooxml-schemas-3.10-FINAL.jar Easily available in net.

jar download page



The above code is working perfectly, please use 3.10 wars those I mentioned above.
 
WHAT is your favorite color? Blue, no yellow, ahhhhhhh! Tiny ad:
Java file APIs (DOC, XLS, PDF, and many more)
https://products.aspose.com/total/java
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!