0

Basically I had a image in the jar file and I got that image url and turned it into a image icon and it worked perfectly this is the code I used

URL resource1 = getClass.getResource(“goldcoin.jpg”);
ImageIcon icon1 = new ImageIcon(resource1);

But I needed to change the image so I changed the old image named it the same and added it to the project and deleted the old one it is the same name and the same file name and it is in the same place. I have tried many things and found a question the same as this but all the answers for it don’t work so please could you help me. Thank you I deleted it and added it again and it worked thanks for your help.

Cufe
  • 18
  • 6
  • It is hard to help you without having way to reproduce your problem. How exactly did you add it to the project? Or "deleted the old one it is the same name"? Did you rebuild your JAR after it and are you sure that new name has exact same characters as old one? And where is that image file actually placed (usually it is better to have some `images` folder which would hold resources you want to use, you would need to use them via `"/images/imageName.jpg"` - more info: [Loading image resource](https://stackoverflow.com/q/9864267)). – Pshemo Aug 31 '18 at 12:53
  • Went on netbeans deleted image then dragged and dropped new image into project then renamed it I didn’t have a image folder I did rebuild it after and the new name is identical to the old one – Cufe Aug 31 '18 at 12:56
  • Hmm. I am not working with NetBeans but maybe renaming image there only sets its name withing project but not on file system OR dragging and dropping doesn't copy image, but provides settings to image in other location (which would be strange but still a possibility). Also are you sure new image is using format which is supported by Java (which based on https://docs.oracle.com/javase/tutorial/2d/images/index.html is GIF, PNG JPEG)? – Pshemo Aug 31 '18 at 12:59
  • The old one and new one both have same ending and I got jar file and used 7zip to see if it was being added properly and using the correct name which it was. It is JPG – Cufe Aug 31 '18 at 13:01
  • I found the problem I decided to delete the image and add a different one and it worked then I realised I changed the file ending from png to jpg which problem made the image not work so now it works – Cufe Aug 31 '18 at 14:34

0 Answers0