0

Edit: I know what a NullPointerException is, the problem is, that docx4j don't finds any elements in the Paragraph Node.

I'm trying to get the first element of the Text Class in a paragraph.

ClassFinder finder = new ClassFinder(P.class);
    new TraversalUtil(model.getWordMLPackage().getMainDocumentPart(),
            finder);
    finder.results.stream().forEach(
            elem -> {

                ClassFinder findfirsttext = new ClassFinder(Text.class);
                new TraversalUtil(elem, findfirsttext);
                Text tt=((Text)findfirsttext.results.get(0));
                System.out.println("asdf"+tt.getValue());

            });

but

                    Text tt=((Text)findfirsttext.results.get(0));

always results in a NullPointerException. Because the util doesn't find text elements in the Paragraph.

Since I'm parsing a valid document every Paragraph should contain at least one Text element.

user2147674
  • 2,319
  • 2
  • 14
  • 17
  • possible duplicate of [What is a Null Pointer Exception, and how do I fix it?](http://stackoverflow.com/questions/218384/what-is-a-null-pointer-exception-and-how-do-i-fix-it) – StackFlowed Dec 31 '14 at 13:37

1 Answers1

2

Looking at code here, you dont have any element in arrayList and you are trying to getValue from null and hence end up in NullPointerException.

SMA
  • 36,381
  • 8
  • 49
  • 73