getSlideByPosition returns null

Hello!


I try to produce a lot of test presentations with aspose.powerpoint java edition

so at the beginnig of the export i create the slides i need.
and later in the programm i take the slide with

Slide temp = pres.getSlideByPosition(slidePosition);

in my example the presentation has 11 slides. but i got a null, when trying to get slide number 2.

is this an error in the api or maybe i have to take the slides in a different way.

Please always provide examples of ppt file in such situation.

i dont have the ppt file, because the export stops with a nullpointer exception.

Do you create this file by yourself?
Could you explain how you do it and why you think it has 11 slides?

  1. i load objects from a database.
    2. i create a presentation from a template
    3. for each object i create a slide by doing this:
    for (int i = 0; i < fo_col.size() - 1; i++) {
    Slide tmps = tmpss.get(0);
    pres.cloneSlide(tmps, pres.getSlides().getLastSlidePosition() + 1);
    }

    4. i fill the slides

Are you sure tmpss.get(0) is normal slide and not “master title slide”?
Try to use tmpss.getSlideByPosition(1) instead.

By the way, you use wrong cloneSlide function.
cloneSlide with 2 parameters can be used for cloning slides inside one presentation only
but you copy slides to another presentation.
As a result you always will have broken ppt files.

alcrus wrote:
By the way, you use wrong cloneSlide function.
cloneSlide with 2 parameters can be used for cloning slides inside one presentation only
but you copy slides to another presentation.
As a result you always will have broken ppt files.


oh, and what is the right way to create a slide?

TreeMap ids = new TreeMap();
tmpss.cloneSlide(tmps, pres.getSlides().getLastSlidePosition() + 1, pres, ids);

1. cloneSlide should called from source presentation. tmpss.cloneSlide(…);
2. 3d param is target presentation. pres
3. last parameter is empty TreeMap or even null if you don’t need to control how masters will be cloned.

if i open a template by doing this:
Presentation template = new Presentation(new FileInputStream(new File(“templates/BSH.pot”)));

then clone some slides:
Slides tmpss = template.getSlides();
for (int i = 0; i < 2; i++) {
Slide tmps = tmpss.get(0);
template.cloneSlide(tmps, template.getSlides().getLastSlidePosition() + 1);
}

and after some work with the presentation i do a:

template.write(“other.ppt”);


this seems to be ok for me and the presentation is not broken.
but is this the right way??

Please replace
Slide tmps = tmpss.get(0);
with
Slide tmps = tmpss.getSlideByPosition(1);

Other things are ok in this example.