• Create Account

### #ActualKyan

Posted 29 April 2012 - 11:35 PM

Could it also have something to do with the fact that in NetBeans the java/class files are in one package and the images are in a sub package. ie. platform.game has all the java files, while platform.game.Assets.Backgrounds has the image I want

If you have your media embedded in a package, then you need to use getResource(URL) to access it from within the archive. E.g.
public MainMenu(String bg){
// the "/" character specifies the root of your package hierarchy
final URL myURL = MainMenu.class.getResource("/platform/game/Assets/Backgrounds/myImage.jpg");
this.bg = Toolkit.getDefaultToolkit().getImage(myURL);
}


The other way to resolve this is to move your image directory outside your package structure. E.g.

Root Directory
• platform
• game
• assets
• backgrounds
Netbeans should easily allow you to create additional folders. I also created a simple example to test this (BufferStrategy + Image loading) and it worked fine.

Edit: Fixed path.

### #1Kyan

Posted 29 April 2012 - 11:34 PM

Could it also have something to do with the fact that in NetBeans the java/class files are in one package and the images are in a sub package. ie. platform.game has all the java files, while platform.game.Assets.Backgrounds has the image I want

If you have your media embedded in a package, then you need to use getResource(URL) to access it from within the archive. E.g.
public MainMenu(String bg){
// the "/" character specifies the root of your package hierarchy
final URL myURL = MainMenu.class.getResource("/platform.game.Assets.Backgrounds.myImage.jpg");
this.bg = Toolkit.getDefaultToolkit().getImage(myURL);
}


The other way to resolve this is to move your image directory outside your package structure. E.g.

Root Directory
• platform
• game
• assets
• backgrounds
Netbeans should easily allow you to create additional folders. I also created a simple example to test this (BufferStrategy + Image loading) and it worked fine.

PARTNERS