Ask coding questions

← Back to all posts
Can someone tell me what’s wrong with my code?
MINHTO

I try to set an ImageIcon to my JButton, but it seems to not work. An IOException is thrown. The code where I give the button the icon is in the Display class. The code where I load in the BufferedImage and then convert it into an ImageIcon is in the Asset class.

I suspect that the problem lies in the way that I type the path, but I do not know the specifics.

Voters
MINHTO
Comments
hotnewtop
Geocube101

On line 13 in Assets.java, I removed the leading slash / and changed the extension to jpeg as there is no file called res/res_square.jpg. It didn't throw any errors then

mwilki7

Does your Display.java file need to do any importing on Asset.java?
It has been a while since I did Java stuff.

SixBeeps

@mwilki7 He doesn't need to import the class, no.
SOURCE: I work with Java daily.