1

I have two similar codes to populate the image array. This one works:

for (int i = 0; i < num_of_slides; i++) //populate an array to hold original size images for each slide
{
        var fileName = @dir + (i + 1) + ".png";
        var bitmap = new BitmapImage(new Uri(fileName)); //{ /*.. more bitmap image options if you like .. */ };
        Image image = new Image() { Source = bitmap /*.. more image options ..*/ };

        image_array[i] = image;
}

But this one:

for (int i = 0; i < 4; i++) //populate an array to hold original size images for each slide
{    
        var fileName = @"/Images/"+i+".jpg";
        var bitmap = new BitmapImage(new Uri(fileName, UriKind.Relative)); //{ /*.. more bitmap image options if you like .. */ };
        Image studio_image = new Image() { Source = bitmap /*.. more image options ..*/ };

        custom_studio_images[i] = studio_image;    
}

crashes at custom_studio_images[i] = studio_image;

saying that it is not set to an instance of an object. I would appreciate any help or suggestion.

Soner Gönül
  • 97,193
  • 102
  • 206
  • 364
Ivan
  • 1,081
  • 2
  • 17
  • 43
  • There is something null. you should check what is the null object. it can be the `custom_studio_images` object. where is it initialized? – Ghyath Serhal Jul 07 '15 at 10:05
  • what is `custom_studio_images`? Can you show as how you initialize this variable? – Paweł Mach Jul 07 '15 at 10:06
  • Does the location in filename in your second example exist? – Saragis Jul 07 '15 at 10:08
  • "Saying that it is not set to an instance of an object" - well of the two variables the second doesn't need to be set to an instance of an object for that line to run so that should lead you to ask if the first was actually set to an instance of an object. Was it? – Chris Jul 07 '15 at 10:12

0 Answers0