OK, I'll paste the code in here instead:

import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.util.Iterator;

import org.apache.poi.xwpf.usermodel.XWPFDocument;
import org.apache.poi.xwpf.usermodel.XWPFParagraph;
import org.apache.poi.xwpf.usermodel.XWPFRun;

public class RunTest {

        private static final String INPUT_FILE_NAME = "C:\\input.docx";
        private static final String OUTPUT_FILE_NAME = "C:\\output.docx";

        public static void main(final String[] args) {
                try {
                        final XWPFDocument doc = new XWPFDocument(new 
FileInputStream(INPUT_FILE_NAME));
                        final Iterator<XWPFParagraph> paragraphs = 
doc.getParagraphsIterator();
                        while (paragraphs.hasNext()) {
                                final XWPFParagraph paragraph = 
paragraphs.next();
                                for (final XWPFRun run : paragraph.getRuns()) {
                                        if (run != null) {
                                                final String text = 
run.getText(0);
                                                if (text != null) {
                                                        
run.setFontFamily("Times New Roman");
                                                }
                                        }
                                }
                        }
                        doc.write(new FileOutputStream(OUTPUT_FILE_NAME));
                } catch (final Exception e) {
                        e.printStackTrace();
                }
        }
}

-----Original Message-----
From: John Turnbull [mailto:[email protected]] 
Sent: Tuesday, 6 December 2011 1:47 PM
To: POI Users List
Subject: RE: NPE setting font family for a XWPFRun

Hmm, the test case seemed to not make it on to the list.  I'll try again now.

-----Original Message-----
From: John Turnbull [mailto:[email protected]] 
Sent: Tuesday, 6 December 2011 1:44 PM
To: POI Users List
Subject: RE: NPE setting font family for a XWPFRun

Hi Nick,

I have attached a simple test case and a stripped-down version of the document 
in question which always crashes as previously described.  Please let me know 
if it crashes for you as well.

-jct

P.S. I hope this list takes attachments!

-----Original Message-----
From: Nick Burch [mailto:[email protected]]
Sent: Tuesday, 6 December 2011 12:24 PM
To: POI Users List
Subject: Re: NPE setting font family for a XWPFRun

On Tue, 6 Dec 2011, John Turnbull wrote:
> The font exists and the run's text is not null so why would this fail? 
> I cannot locate the source in question but the actual exception is:
>
> java.lang.NullPointerException
>                at 
> org.apache.poi.xwpf.usermodel.XWPFRun.setFontFamily(XWPFRun.java:465)

I can't see anything obviously wrong with that line that would cause this. 
Are you able to create a simple unit test that shows the problem?

Nick

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected] For additional 
commands, e-mail: [email protected]



---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to