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 Problem
Page Index Toggle Pages: 1
loadImage Problem (Read 378 times)
loadImage Problem
Apr 28th, 2008, 4:16pm
 
Hi guys, I have a multi-class program (separate files for each class) and I can only load jpegs in the main file. If I try to load the same image inside of the classes then it says that the file "f.jpg" is missing or inaccessible (????)

Does anyone know how to fix this??

 Thanks in advance.
Re: loadImage Problem
Reply #1 - Apr 28th, 2008, 10:33pm
 
it's probably because of the way you're declaring things.  Make sure you declare the image globally in the main section of your class and then initialize it in one of the constructors or methods. post some code so we can see where the problem is.
Re: loadImage Problem
Reply #2 - Apr 29th, 2008, 10:26am
 
 Thanks for the help! Sorry for not being more specific.
 I have this folowing class, for now I am just trying to get it to draw an image on the screen. but it's not working.  
 You mean that I have to declare the PImage variable as a global for the hole program? I really don't like that!

-------------------------------------------
class MarkerScreen extends Screen
{
 PImage backgroundImage;
 
 MarkerScreen()
 {
   backgroundImage = loadImage("f.jpg");
 }
 
 void drawScreen()
 {
   image(backgroundImage, 0, 0);
 }
}
-----------------------------------------------
Re: loadImage Problem
Reply #3 - Apr 29th, 2008, 5:58pm
 
Problem solved,

  The thing is that you can't run the construct on the global definition of the variable.

 So you just declare all your global variables but you can only instanciate them in the setup() method

 I don't know if it's clear... just avoid this at all costs:

--------------------
MyClass variableName = new MyClass();

void setup()
{
}
--------------------


and try to do this all the times:

--------------------
MyClass variableName;

void setup()
{
 variableName = new MyClass();
}
--------------------

Hope it helps someone!!

see you!!
Page Index Toggle Pages: 1