Where to put image for settings.setIcons

hello

as i try to set my app icon,

settings.setIcons(new BufferedImage[]{ImageIO.read( Main.class.getResourceAsStream(“icon.png”))});

i keep getting a null pointer for the resource

so i was wondering where am i supposed to put the icon and will it be available at runtime like the asset folder

i tried the root folder, the src folder, the asset folder, i am getting out of ideas :frowning:

thx

Well, what I do is put all my icon images into a package. Then you can load them as a resource.

BufferedImage[] read = {ImageIO.read(app.getClass().getResourceAsStream("/com/lastabyss/resources/flame.png"))};

EDIT: Code tags are broken, had to remove them

In this case, the images would be in the package com.lastabyss.resources

Just remember to put the “/” at the beginning of the path if you’re putting it in a package.

<cite>@navid113 said:</cite> Well, what I do is put all my icon images into a package. Then you can load them as a resource.

BufferedImage read = {ImageIO.read(app.getClass().getResourceAsStream(“/com/lastabyss/resources/flame.png”))};

EDIT: Code tags are broken, had to remove them

In this case, the images would be in the package com.lastabyss.resources

Just remember to put the “/” at the beginning of the path if you’re putting it in a package.

thx

but althought it seems to find the file, it does not change the icon anywhere
i checked the window icon and the exe file icon but it is still the default one

i tried to save the settings with

try { settings.save(“com.foo.MyCoolGame3”); }
catch (BackingStoreException ex) { /** could not save settings */ }

but with no luck

@curtisnewton said: hello

as i try to set my app icon,

settings.setIcons(new BufferedImage{ImageIO.read( Main.class.getResourceAsStream(“icon.png”))});

i keep getting a null pointer for the resource

so i was wondering where am i supposed to put the icon and will it be available at runtime like the asset folder

i tried the root folder, the src folder, the asset folder, i am getting out of ideas :frowning:

thx

What is the resource? If you get NPE for it then it’s not where you think it is. Your line indicates that it should be in the same directory as the Main.class file, ie: in that package. I don’t remember if the build copies the png files as resources by default and you may have to tweak the project settings.

<cite>@pspeed said:</cite> What is the resource? If you get NPE for it then it's not where you think it is. Your line indicates that it should be in the same directory as the Main.class file, ie: in that package. I don't remember if the build copies the png files as resources by default and you may have to tweak the project settings.

well i got it working as it seems to see the file but it does not change the icon anywhere

i tried to save my settings to the registry, but i still dont see the icon on the main window

This always worked for me:
[java]
BufferedImage[] icons = new BufferedImage[] {
ImageIO.read( MainStart.class.getResource( “globe-128.png” ) ),
ImageIO.read( MainStart.class.getResource( “globe-32.png” ) ),
ImageIO.read( MainStart.class.getResource( “globe-16.png” ) )
};
settings.setIcons(icons);
[/java]

<cite>@pspeed said:</cite> This always worked for me: [java] BufferedImage[] icons = new BufferedImage[] { ImageIO.read( MainStart.class.getResource( "globe-128.png" ) ), ImageIO.read( MainStart.class.getResource( "globe-32.png" ) ), ImageIO.read( MainStart.class.getResource( "globe-16.png" ) ) }; settings.setIcons(icons); [/java]

thx, ill check that out… i only set 1 icon so maybe it is the issue