java.lang.NullPointerException is thrown by getOleFormat

@tahir.manzoor
I use above code but it throw the NULL Pointer Exception
"
Exception in thread “main” java.lang.NullPointerException
at com.sps.test.EmbbedImage.main(EmbbedImage.java:20)"

Line no 20: if(oleFormat.getProgId() == “Excel.Sheet.12”)

@rjnick

Please ZIP and attach your input and expected output documents here for testing. We will investigate the issue and provide you more information on it.

1 Like

@tahir.manzoor

Desktop.zip (124.3 KB)

@rjnick

Your input document does not contain the embedded object. Please open your document in MS Word and right click on it to edit it. You will notice that it is not OLE object.

You can check either Shape.OleFormat property returns null or not as shown below to avoid the shared exception.

OleFormat oleFormat = shape.getOleFormat();
if(oleFormat != null && oleFormat.getProgId() == "Excel.Sheet.12")
{
    //Your code...
}