Referencing Files within Src

Trying to initialise an image object using the following:


land = new Image("com.westloar.testing1/assets/land.jpg");

land.jpg is in the following file structure:

testing1/src/com.westloar.testing1/com.westloar.testing1.assets

I realise this is such a noob question but I can’t seem to work out why it can’t find the image :expressionless:

I have never put assets in the source. I don’t think it’s a good idea, but here’s some debugging help:

Use System.out.println to find the full path.

If it isn’t what you’re expecting, change it until it does.

Are you trying to load an image from the internet or from your own computer? I think your command would look for the image in:
/com.westloar.testing1/assets/land.jpg

Is that what you intend? Or perhaps you meant:

land = new Image("assets/land.jpg");

Which would look for the file at:

/assets/land.jpg

yer I tried that just before you posted and it still wouldn’t work, then the solution hit me:

such a fail mistake, replaced “.” with “/” and now it finds the file.

probably couldn’t find the file, because I was POINTING IT AT A NON-EXISTENT FILE :\

noob.

Use


land = new ImageIcon("com/westloar/testing1/assets/land.jpg").getImage();

Haha, similar mistakes happened to me like 1000 times I think. So obvious that you overlook it.