Null pointer exception when call Slide.getNotesTextFrame() method

when we call getNotesTextFrame(), it will return null pointer if the slide contains no TextFrame.



question: does there exist hasTextFrame() method?

Hi,

I have observed the information shared. It seems that your source presentation does not have notes slide probably and you are trying to access the TextFrame for that. For this reason, you are probably getting the exception. Please share the source presentation along with working sample code to reproduce the issue on our end. I will investigate the issue further on my end to help you out.

Many Thanks,

the ppt file is ease to create, just add a slide, don’t modify anything, then save the file.



The java code call is just get the slide call getNotesTextFrame(). Something like: slide.getNotesTextFrame(); It will return null pointer.



I see in .net, aspose have a check function such as slide.hasTextFrame(); but in java I don’t see this function.



We prefer to check to see if the slide contains a TextFrame instead of handling the null pointer exception. So just want to confirm with you see if there exist someway better than just handle the null pointer exception.



Hope you can provide some guidancy.





Thanks.

Hi,

I have observed the comments shared by you and suggest you to please try using the following sample code on your end to serve the purpose. You need to put check on availability of NotesSlide that if that is null or available.

Presentation presentation = new Presentation();
ISlide sld=presentation.getSlides().get_Item(0);

INotesSlide note=null;
if(sld.getNotesSlide()==null)

note=sld.addNotesSlide();
else
note=sld.getNotesSlide();

ITextFrame textFrame=note.getNotesTextFrame();

Many Thanks,

Hi Mudassir,



that is not what I want. maybe you did not understand my point. as the last line of code you suggested:

ITextFrame textFrame=note.getNotesTextFrame();



this textFrame could be null.



it is not the power point file does not have a slide, it is a slide does not contain TextFrame. do I confuse you ?



my question is: does there exist some method such as note.hasTextFrame() in java.



purpose is we try to avoid dealing with null.

Hi,

I have observed your further comments and regret to share that is no property available in my knowledge with name hasTextFrame in .NET. I request you to please share the working .NET sample that is working as per your aspirations and I will port that for you in compliance with Aspose.Slides for Java. As far your requirement is concerned you may try using the following alternate on your end as well.

Presentation presentation = new Presentation();
ISlide sld=presentation.getSlides().get_Item(0);

INotesSlide note=null;
if(sld.getNotesSlide()==null)

note=sld.addNotesSlide();
else
note=sld.getNotesSlide();

if(note.getNotesTextFrame()!=null)
{
ITextFrame textFrame=note.getNotesTextFrame();

}

Many Thanks,

foreach (var item in presentation.Slides[1].Shapes)

{

var shape = (Microsoft.Office.Interop.PowerPoint.Shape)item;

if (shape.HasTextFrame == MsoTriState.msoTrue)

{

if (shape.TextFrame.HasText == MsoTriState.msoTrue)

{

var textRange = shape.TextFrame.TextRange;

var text = textRange.Text;



presentation_textforParent += text + " ";

}

}

}





the first if.

Hi,

I have observed your requirement. You have shared Microsoft Interop code. The sample code that I have shared pretty much does the same for you but you are probably not interested in checking null. I have created an issue with ID SLIDESJAVA-34955 as new feature request to provide the support for checking TextFrame. This thread has been linked with the issue so that you may be automatically notified once the support will be available.

public static void ExtractText()
{
Presentation presentation=new Presentation(“test.pptx”);

for (IShape item : presentation.getSlides().get_Item(1).getShapes())
{
if(item instanceof IAutoShape)
{
IAutoShape shape = (IAutoShape)item;
if (shape.getTextFrame()!= null)
{
ITextFrame textRange = shape.getTextFrame();
if(textRange.getText().length()>0)
{
String text = textRange.getText();

presentation_textforParent += text + " ";
}
}

}

}

}


Many Thanks,