Free Support Forum -

[JAVA] NullPointerException Issues

I am experiencing some problems with the JAVA library when i use the Slide.saveToSVG() method with the attached .ppt, it throws a NullPointerException.

Heres the code I use

for (int i = 1 ; i <= currentSlides.size() ; i++)
System.out.println("Begining the process of " + "Slide" + i);
com.aspose.slides.Slide tempSlide = currentPresentation.getSlideByPosition(i);

if (tempSlide == null)

System.out.println("Converting to SVG " + "Slide" + i);
//Converts the slide to the SVG format
File svgSlide = new File(Config.BASE_PATH + File.separator + tempId + File.separator + Config.SLIDE_FOLDER_NAME + File.separator + "slide" + i + ".svg");
FileOutputStream svgSlideOutputStream = new FileOutputStream(svgSlide);


Here's the log

Begining the process of Slide1 Converting to SVG Slide1 java.lang.NullPointerException at at com.aspose.slides.dG.if(SourceFile:1855) at com.aspose.slides.dG.goto(SourceFile:1837) at at at at com.aspose.slides.Slide.saveToSVG(SourceFile:1475) at com.aspose.slides.Slide.saveToSVG(SourceFile:1458)

This may be a related issue… I’m attempting to generate a set of images from the slides, similar to the code above. On one particular slide in the presentation, saveToSVG throws the following exception:

at com.aspose.slides.Slide.saveToSVG(SourceFile:1475)
at com.aspose.slides.Slide.saveToSVG(SourceFile:1458)

My code catches the exception, and I can generate the rest of the slides with no further problems. We deleted the slide and re-created it in the .PPT, and the problem vanished. I though I’d let you know of the error.



It was fixed in the last 1.5.3 hot fix.

I’m pretty sure I was using that version when that exception was thrown, but I’ll double-check.

If you have such problem with 1.5.3 please attach your presentation.

Hmm. It looks like I didn’t include the new version in my project
correctly. I downloaded just now, and I believe it is properly
used. However, I still see an exception when saveToSVG is called:

at com.aspose.slides.Slide.saveToSVG(SourceFile:1475)
at com.aspose.slides.Slide.saveToSVG(SourceFile:1458)

line numbers were consistent before, and they seem to have changed with
the new apsose.slides.jar. So, I believe I am using the latest .jar,
but still see the exception.

The problematic .ppt is attached.
I managed to clear out the presentation to the point where it is a
single, almost-empty slide, yet still produces the error when saveToSVG
is called.

Sorry to bother you… Has this been looked at? Thanks.

Yes, it’s already fixed and will be published soon. Probably tomorrow.

I wonder if this is related. I am using the same function: slide.saveToSVG and I get a ClassCastException…here is the error message:



at com.aspose.slides.Slide.saveToSVG(SourceFile:1477)

at com.aspose.slides.Slide.saveToSVG(SourceFile:1458)

Is this my error or is this being caused by Aspose.

Thanks so much!

Could you provide ppt file with this error please?

I’ve encountered a new exception… My code takes a presentation and adds slides to it. When I try to re-load the presentation the next time the application runs, I see this error:

at com.aspose.slides.TextHolder.(SourceFile:76)
at com.aspose.slides.Slide.(SourceFile:153)
at com.aspose.slides.Presentation.(SourceFile:407)

The .ppt loads fine in PowerPoint, and re-saving it from PowerPoint allows aspose.slides to successfully load it in. I’ve attached an example .ppt that causes this error.

Edit: I create the new slides by calling Presentation.addBodySlide(), then getting the body shape’s Paragraphs, then adding a series of Paragraphs containing text.

More information on the above post:

I add a body slide so that I can use whatever the default body text style is. There may be another way to find/set it, but I don’t know how. First, I’d get both shapes and placeholders from the slide. Then, I’d remove the first shape from the Shapes object to subtract the header from the slide. Then, I’d cast the body’s Placeholder to a TextHolder and add in whatever text I desire.

After a little testing, it seems that, once saved, a slide that has had a shape removed doesn’t seem to load properly later, perhaps only if the Placeholders are also edited. I’ve noticed, however, that removing a Shape doesn’t decrease the count of the Placeholders object. I’ve gotten the slide editing to work just by hiding the header Shape and resizing the body Shape to fot more of the slide.

Anyway, is there some way to synchronize the Placeholders to the current state of the slide’s Shapes, or to directly remove a Placeholder? I may just not understand how all of these objects interact.

In any case, it seems to work now, so I guess this is just food for thought.

I’d suggest using TextFrames only when it’s possible.
They are more safe and predictable than TextHolders.

I tried using TextFrames, but I couldn’t get them to display anything. I’ll give it another try, though. Thanks.