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 › loadImage null handling problem
Page Index Toggle Pages: 1
loadImage null handling problem (Read 580 times)
loadImage null handling problem
Nov 14th, 2007, 7:49am
 
Im trying to handle loading images that may not exist, I handle the null return from the function.

BUT THE PROGRAM STOPS!!!!

how can  I make it not stop after the red message in the console?

please help

PImage x = loadImage("fotos/"+this.nombre+".jpg");
        if(x != null){
         image(x,this.x,this.y,200,200);
       }
       else{
         println("mostrarFoto2");
       }
Re: loadImage null handling problem
Reply #1 - Nov 14th, 2007, 8:25am
 
PImage x;

try {
   x = loadImage("fotos/"+1+".jpg");
} catch ( Exception e ) {
   x = null;
}
   
if (x != null)
{
    image(x, 5, 5,200,200);
}
else
{
    println("mostrarFoto2");
}


just to let you know:

this.x and x are the same at this level, so you can't do:
image( x, this.x, this.y, 200, 200 );
bacause it says:
draw [image named "x"] at position [image named "x"] .. which is an image not a int / float that you need for the coordinates.

http://www.processing.org/learning/examples/variablescope.html
http://processing.org/reference/this.html

F

(BTW ALL CAPS DOES NOT MAKE US WANT TO ANSWER FASTER)
Re: loadImage null handling problem
Reply #2 - Nov 14th, 2007, 8:32pm
 
hello

tried:

PImage z;
   
   try {
     z = loadImage("fotos/"+this.nombre+".jpg");  
   }
   catch ( Exception e ) {
     z = null;
   }

   if (z != null)
   {  
     image(z,this.x,this.y,200,200);  
   }  
   else
   {  
     println("mostrarFoto2");  
   }

but...still the program stops and I get this red message:

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

please help
Page Index Toggle Pages: 1