# Array of Images Error (loading of images)

**URL:** https://discourse.processing.org/t/array-of-images-error-loading-of-images/26725
**Category:** Coding Questions
**Tags:** homework
**Created:** [January 3, 2021, 4:07pm UTC](https://discourse.processing.org/t/array-of-images-error-loading-of-images/26725 "2021-01-03T16:07:39Z")
**Posts on this page:** 20
**Page:** 1

<div class="post-metadata">

### Author: ![ELaN](https://avatars.discourse-cdn.com/v4/letter/e/3e96dc/32.png) [@ELaN](https://discourse.processing.org/u/ELaN)
#### Post date: [January 3, 2021, 4:07pm UTC](https://discourse.processing.org/t/array-of-images-error-loading-of-images/26725/1 "2021-01-03T16:07:40Z")

</div>

Whenever I write this code:

PImage[] flowers=new PImage[3];  
Bubble[] bubbles=new Bubble[5];

void setup() {  
size(640, 360);  
for(int i=0; i\<flowers.length; i++){  
flowers[i]=loadImage(“flower”+i+".jpg");  
}  
for(int i=0; i\<bubbles.length; i++){  
int index=int(random(0,flowers.length));  
bubbles[i]=new Bubble(flowers[index],100+i\*100, 300, random(32, 72));  
}  
}

void draw() {  
background(255);  
for (int i=0; i\<bubbles.length; i++){  
bubbles[i].display();  
bubbles[i].ascend();  
bubbles[i].top();  
}  
}

AND CLASS:  
class Bubble {  
float x;  
float y;  
float diameter;  
PImage img;

Bubble(PImage tempImg, float tempX, float tempY, float tempD) {  
x=tempX;  
y=tempY;  
diameter=tempD;  
img=tempImg;  
}  
void display() {  
stroke(0);  
fill(127);  
image(img,x, y, diameter, diameter);  
}  
void ascend() {  
y–;  
x=x+random(-2, 2);  
}  
void top() {  
if (y\<diameter/2) {  
y=diameter/2;  
}  
}  
}

I ALWAYS get errors saying ‘‘The file “flower0.jpg” is missing or inaccessible, make sure the URL is valid or that the file has been added to your sketch and is readable.  
The file “flower1.jpg” is missing or inaccessible, make sure the URL is valid or that the file has been added to your sketch and is readable.  
The file “flower2.jpg” is missing or inaccessible, make sure the URL is valid or that the file has been added to your sketch and is readable.  
NullPointerException  
Could not run the sketch (Target VM failed to initialize).  
For more information, read revisions.txt and Help ? Troubleshooting.’’

Even though I have doubled checked on how and where I saved the images (name etc) I still can’t get past this.

---

<div class="post-metadata">

### Author: ![josephh](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/josephh/32/210_2.png) [@josephh](https://discourse.processing.org/u/josephh)
#### Post date: [January 3, 2021, 9:18pm UTC](https://discourse.processing.org/t/array-of-images-error-loading-of-images/26725/2 "2021-01-03T21:18:51Z")

</div>

Hi,

Welcome to the community! 🙂

If your project is named `sketch`, you should have the following folder structure :

```auto
sketch
├── data
│ ├── flower0.jpg
│ ├── flower1.jpg
│ └── flower2.jpg
└── sketch.pde

1 directory, 4 files

```

Your images need to be in a `data` folder inside your sketch folder, then it should work.

If you are on Linux or Mac, can you use the `tree` command in the terminal (used above) to show the file structure of your project?

---

<div class="post-metadata">

### Author: ![Chrisir](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/chrisir/32/45_2.png) [@Chrisir](https://discourse.processing.org/u/Chrisir)
#### Post date: [January 3, 2021, 10:16pm UTC](https://discourse.processing.org/t/array-of-images-error-loading-of-images/26725/3 "2021-01-03T22:16:13Z")

</div>

Also, it’s case sensitive, so jpg not equal JPG

your program works for me, I just run it

---

<div class="post-metadata">

### Author: ![ELaN](https://avatars.discourse-cdn.com/v4/letter/e/3e96dc/32.png) [@ELaN](https://discourse.processing.org/u/ELaN)
#### Post date: [January 4, 2021, 1:21pm UTC](https://discourse.processing.org/t/array-of-images-error-loading-of-images/26725/4 "2021-01-04T13:21:20Z")

</div>

All I see is a file names sketch and inside that file there is the file with the processing code, another processing code file that exists because I wrote the class on a different tab inside processing and nothing else. There is no data folder. I made a folder inside that folder and put my images inside and it still doesn’t work.

---

<div class="post-metadata">

### Author: ![ELaN](https://avatars.discourse-cdn.com/v4/letter/e/3e96dc/32.png) [@ELaN](https://discourse.processing.org/u/ELaN)
#### Post date: [January 4, 2021, 1:22pm UTC](https://discourse.processing.org/t/array-of-images-error-loading-of-images/26725/5 "2021-01-04T13:22:25Z")

</div>

I tried it with .JPG and .jpg and none of it works

---

<div class="post-metadata">

### Author: ![Chrisir](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/chrisir/32/45_2.png) [@Chrisir](https://discourse.processing.org/u/Chrisir)
#### Post date: [January 4, 2021, 1:26pm UTC](https://discourse.processing.org/t/array-of-images-error-loading-of-images/26725/6 "2021-01-04T13:26:05Z")

</div>

You must copy the images in your Sketch folder

---

<div class="post-metadata">

### Author: ![ELaN](https://avatars.discourse-cdn.com/v4/letter/e/3e96dc/32.png) [@ELaN](https://discourse.processing.org/u/ELaN)
#### Post date: [January 4, 2021, 1:26pm UTC](https://discourse.processing.org/t/array-of-images-error-loading-of-images/26725/7 "2021-01-04T13:26:53Z")

</div>

I did that and it won’t work

---

<div class="post-metadata">

### Author: ![Chrisir](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/chrisir/32/45_2.png) [@Chrisir](https://discourse.processing.org/u/Chrisir)
#### Post date: [January 4, 2021, 1:46pm UTC](https://discourse.processing.org/t/array-of-images-error-loading-of-images/26725/8 "2021-01-04T13:46:46Z")

</div>

Do you have maybe F or f flower?

---

<div class="post-metadata">

### Author: ![Chrisir](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/chrisir/32/45_2.png) [@Chrisir](https://discourse.processing.org/u/Chrisir)
#### Post date: [January 4, 2021, 1:55pm UTC](https://discourse.processing.org/t/array-of-images-error-loading-of-images/26725/9 "2021-01-04T13:55:21Z")

</div>

what does this print please:

```auto

void setup() {
  size(770, 770);
  PImage[] list = loadImages();
  println (list.length);
  image(list[0], 0, 0);
}

PImage[] loadImages() {
  java.io.File folder = new java.io.File(dataPath("")+"/");
  String[] filenames = folder.list();
  PImage[] img = new PImage[filenames.length];
  for (int i = 0; i < filenames.length; i++) {
    println(dataPath("") + "/" + filenames[i]); 
    img[i] = loadImage(dataPath("") + "/" + filenames[i]);
  }
  return img;
}

```

---

<div class="post-metadata">

### Author: ![ELaN](https://avatars.discourse-cdn.com/v4/letter/e/3e96dc/32.png) [@ELaN](https://discourse.processing.org/u/ELaN)
#### Post date: [January 4, 2021, 3:36pm UTC](https://discourse.processing.org/t/array-of-images-error-loading-of-images/26725/10 "2021-01-04T15:36:24Z")

</div>

If I run what you wrote it highlights PImage[] img = new PImage[filenames.length];  
and gives me NullPointerException error.

---

<div class="post-metadata">

### Author: ![Chrisir](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/chrisir/32/45_2.png) [@Chrisir](https://discourse.processing.org/u/Chrisir)
#### Post date: [January 4, 2021, 3:42pm UTC](https://discourse.processing.org/t/array-of-images-error-loading-of-images/26725/11 "2021-01-04T15:42:42Z")

</div>

are you sure you have a folder data in your Sketch’s folder???

What happens when you press **ctrl-k** in your Sketch?

---

<div class="post-metadata">

### Author: ![ELaN](https://avatars.discourse-cdn.com/v4/letter/e/3e96dc/32.png) [@ELaN](https://discourse.processing.org/u/ELaN)
#### Post date: [January 4, 2021, 3:44pm UTC](https://discourse.processing.org/t/array-of-images-error-loading-of-images/26725/12 "2021-01-04T15:44:41Z")

</div>

the folder in which the sketch and the folder data (with the images) are opens up

---

<div class="post-metadata">

### Author: ![Chrisir](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/chrisir/32/45_2.png) [@Chrisir](https://discourse.processing.org/u/Chrisir)
#### Post date: [January 4, 2021, 3:48pm UTC](https://discourse.processing.org/t/array-of-images-error-loading-of-images/26725/13 "2021-01-04T15:48:18Z")

</div>

then the example Sketch should show something

Did you write “data” with small letters only?

```auto
void setup() {
  size(770, 770);

  PImage[] list = loadImages();
  println (list.length);

  if (list.length>0) 
    image(list[0], 0, 0);
  else println ("no image found");
}

PImage[] loadImages() {
  java.io.File folder = new java.io.File(dataPath("")+"/");
  String[] filenames = folder.list();

  PImage[] img = new PImage[filenames.length];
  for (int i = 0; i < filenames.length; i++) {
    println(dataPath("") + "/" + filenames[i]); 
    img[i] = loadImage(dataPath("") + "/" + filenames[i]);
  }
  return img;
}

```

---

<div class="post-metadata">

### Author: ![Chrisir](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/chrisir/32/45_2.png) [@Chrisir](https://discourse.processing.org/u/Chrisir)
#### Post date: [January 4, 2021, 3:52pm UTC](https://discourse.processing.org/t/array-of-images-error-loading-of-images/26725/14 "2021-01-04T15:52:46Z")

</div>

Weird. It runs on my computer.

Are you on Win 10 ?

---

<div class="post-metadata">

### Author: ![Chrisir](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/chrisir/32/45_2.png) [@Chrisir](https://discourse.processing.org/u/Chrisir)
#### Post date: [January 4, 2021, 3:59pm UTC](https://discourse.processing.org/t/array-of-images-error-loading-of-images/26725/15 "2021-01-04T15:59:39Z")

</div>

Besides, I can run your initial Sketch with images even without the data folder,  
when the 3 images just are in your Sketch folder.

---

<div class="post-metadata">

### Author: ![ELaN](https://avatars.discourse-cdn.com/v4/letter/e/3e96dc/32.png) [@ELaN](https://discourse.processing.org/u/ELaN)
#### Post date: [January 4, 2021, 4:03pm UTC](https://discourse.processing.org/t/array-of-images-error-loading-of-images/26725/16 "2021-01-04T16:03:33Z")

</div>

Ok so the second code you wrote runs just fine and the corresponding image appears. And yes i’m on win 10 and the file name is data small letters

---

<div class="post-metadata">

### Author: ![Chrisir](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/chrisir/32/45_2.png) [@Chrisir](https://discourse.processing.org/u/Chrisir)
#### Post date: [January 4, 2021, 4:06pm UTC](https://discourse.processing.org/t/array-of-images-error-loading-of-images/26725/17 "2021-01-04T16:06:48Z")

</div>

ok, so the second code runs with the images flower0, flowers1 and flowers2

The same images from your initial Sketch / game?

What does this print please?

```auto

void setup() {
  size(770, 770);

  PImage[] list = loadImages();
  println (list.length);

  if (list.length>0) 
    image(list[0], 0, 0);
  else {
    println ("no image found");
  }
}

PImage[] loadImages() {
  java.io.File folder = new java.io.File(dataPath("")+"/");
  String[] filenames = folder.list();

  PImage[] img = new PImage[filenames.length];
  for (int i = 0; i < filenames.length; i++) {
    println(dataPath("") + "/" + filenames[i]); 
    img[i] = loadImage(dataPath("") + "/" + filenames[i]);
  }
  return img;
}

```

---

<div class="post-metadata">

### Author: ![ELaN](https://avatars.discourse-cdn.com/v4/letter/e/3e96dc/32.png) [@ELaN](https://discourse.processing.org/u/ELaN)
#### Post date: [January 4, 2021, 4:11pm UTC](https://discourse.processing.org/t/array-of-images-error-loading-of-images/26725/18 "2021-01-04T16:11:36Z")

</div>

Yes the correspoding images appears (same as the ones I was trying to use before) and this message prints C:\Users\USER\AppData\Local\Temp\untitled4877301069392334631sketches\sketch\_210104a\data/flower0.jpg.jpeg  
C:\Users\USER\AppData\Local\Temp\untitled4877301069392334631sketches\sketch\_210104a\data/flower1.jpg.jpg  
C:\Users\USER\AppData\Local\Temp\untitled4877301069392334631sketches\sketch\_210104a\data/flower2.jpg.jpg  
3

---

<div class="post-metadata">

### Author: ![Chrisir](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/chrisir/32/45_2.png) [@Chrisir](https://discourse.processing.org/u/Chrisir)
#### Post date: [January 4, 2021, 4:12pm UTC](https://discourse.processing.org/t/array-of-images-error-loading-of-images/26725/19 "2021-01-04T16:12:12Z")

</div>

> [@ELaN](#):
>
> flower2.jpg.jpg

Thanks

What’s wrong with the file name here?

Please rename 3 files and try initial Sketch again.

---

<div class="post-metadata">

### Author: ![ELaN](https://avatars.discourse-cdn.com/v4/letter/e/3e96dc/32.png) [@ELaN](https://discourse.processing.org/u/ELaN)
#### Post date: [January 4, 2021, 4:13pm UTC](https://discourse.processing.org/t/array-of-images-error-loading-of-images/26725/20 "2021-01-04T16:13:56Z")

</div>

wait so it should be flower0.jpg.jpg instead of flower0.jpg? did i understand correctly?

[Next page](https://discourse.processing.org/t/array-of-images-error-loading-of-images/26725.md?page=2)
