We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexProgramming Questions & HelpSyntax Questions › help with loadImage()
Page Index Toggle Pages: 1
help with loadImage() (Read 495 times)
help with loadImage()
Apr 2nd, 2009, 8:24am
 
I am having a problem I can't debug.  I've loaded a string array with the .jpg file names, I'm trying to load an image array with the .jpg files named in the string array, and for some reason Processing will not load the images.  I've put the .jpg files in the same folder with the .pde, and in a data folder, and in an images folder.  I'm guessing it's something I'm just *not* seeing.  Here are the lines I'm working with.. .

PImage[] iBalast = new PImage[21];
String[] sBalast = {"Balast_00.jpg","Balast_05.jpg",  .  .  .  ,"Balast_100.jpg"};    
 BalastTank(String n, int x, int y) {
   bName = n + "Balast"; print("Loading " + bName + " images: ");
   for (int i=0; i<sBalast.length; i+=1) {
     iBalast[i] = loadImage(sBalast[i]);
   }


This part of the code worked fine in an earlier version, just not working in the current version.  The only difference is this is within a class object.
Re: help with loadImage()
Reply #1 - Apr 2nd, 2009, 11:46am
 
The code looks fine, but it depends where it is called. If that's within a method of a class, the arrays must be defined as class fields, so they persist after exiting the function.
Re: help with loadImage()
Reply #2 - Apr 6th, 2009, 1:53pm
 
I thought I did, here's a little more of the class..

class BalastTank {
 int bX, bY;
 int bW, bH;
 int FillLevel;
 String bName;
 PImage iBalast[] = new PImage[21];
 String sBalast[] = { "Balast_00.jpg", "Balast_05.jpg", . . . , "Balast_100.jpg" };    
 BalastTank(String n, int x, int y) {
   bName = n + "Balast";
   for (int i=0; i<sBalast.length; i+=1) {
     iBalast[i] = loadImage(sBalast[i], "jpg");
   }
   bW = iBalast[0].width;
   bH = iBalast[0].height;
   bX = constrain(x, 0, width-iBalast[0].width);
   bY = constrain(y, 0, height-iBalast[0].height);
   FillLevel = 0;
 }


I'm getting the feeling that I need to assign values in the function call, not the class header.  I'm sorry if this is a little elementary, I am new after all.

This is the error message it keeps giving me...

The file "Balast_00.jpg" is missing or inaccessible, make sure the URL is valid or that the file has been added to your sketch and is readable.

it gives this message for each of the .jpg files in sBalast[]
Page Index Toggle Pages: 1