NullException while creating document -- TextBlock.GetBody
See original GitHub issueThank you very much for this project.
I have problem using it though, because right at the start, when you are loading/creating the document with DocumentFactory.Create
I got null exception. The issue is with TextBlock.GetBody
and its loop while (nextElement != endParent)
.
Inside the body there is soft casting to OpenXmlCompositeElement
on the assumption that every element is indeed OpenXmlCompositeElement
, but if it is not the case, the outcome of the cast would be null, and on next iteration null exception will be thrown.
And in my case it is what happens, at one point DocumentFormat.OpenXml.Wordprocessing.BookmarkEnd
appears (it does not inherit from OpenXmlCompositeElement
).
Issue Analytics
- State:
- Created 2 years ago
- Comments:5 (3 by maintainers)
Top Results From Across the Web
XWPFWordExtractor.getText() throws NullPointerException
However, that itself throws a NullPointerException because it tries to access the "SectPr" of the document via doc.getDocument().getBody().
Read more >RetrofitError: getBody can throw a NullPointerException #405
It seems they're in between implementations for JUnit in Android Studio - creating tests isn't a right click away anymore, or maybe I...
Read more >Handling Java NullPointerException and Best Practices
NullPointerException is a runtime condition where we try to access or modify an object which has not been initialized yet. It essentially means ......
Read more >How to fix Attempt to de-reference a null object in test for ...
This is pretty straightforward. Your code is designed to return a null value given an invalid response, and that's exactly what it's doing....
Read more >Null Pointer Exception In Java
NullPointerException is thrown when program attempts to use an object reference that has the null value. These can be: Invoking a method from...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Could you also post how you’re calling SharpDocx? I guess you’re doing something like:
instead of
DocumentFactory needs to know the type of the model. If it doesn’t, it will generate
public string Model { get; set; }
instead ofpublic MyViewModelType Model { get; set; }
. Which will lead to a compilation error inforeach (var sensor in Model.Sensors)
.Many thanks for the update. Indeed I had such combo
and the first one failed. Now I have
Create
with two arguments as you shown, and the creation was successful. So I think it is safe to close this report as fixed. Once again, thank you very much!