In the future, please try to post a MCVE. The code you posted now is not valid syntax and doesn't really reflect what you're actually doing.
Anyway, the loadImage()
function is not static, so you can't do this:
PApplet.loadImage("img.jpg");
And it's also worth noting that every sketch extends the PApplet
class, so this:
PImage img;
void setup(){
img = loadImage("img.jpg");
}
Is converted to Java code that looks like this:
public class MySketch extends PApplet{
PImage img;
void setup(){
img = loadImage("img.jpg");
}
}
Here, we can see that the loadImage()
function is coming from the PApplet
class, which we're extending.
So now you have something like this:
public class MySketch extends PApplet{
PImage img;
void setup(){
img = MyInnerClass.getImage("img.jpg");
}
class MyInnerClass{
public static PImage getImage(String loc){
return loadImage(loc);
}
}
}
Or something like this:
public class MySketch extends PApplet{
PImage img;
void setup(){
img = new MyInnerClass().getImage("img.jpg");
}
static class MyInnerClass{
public PImage getImage(String loc){
return loadImage(loc);
}
}
}
In either case, this will generate an error saying that you can't use the non-static loadImage()
function from a static context.
That's because the loadImage()
function is coming from the instance itself. You need an instance to use a non-static function. But since the getImage()
function is static, it doesn't belong to any particular instance. That's why it doesn't work.
If I were you, I would take a step back and ask yourself why you need inner classes at all. If it's a static function, then why not just use a sketch-level function?