This week's book giveaway is in the OCAJP 8 forum. We're giving away four copies of OCA Java SE 8 Programmer I Study Guide and have Edward Finegan & Robert Liguori on-line! See this thread for details.
at javac.imageio.ImageIO.read(Unknown Source) at FrameImagePanel.loadImage(FrameImage.java:66) at FrameImagePanel.<init>(FrameImage.java:40) at FrameImage.<init>(FrameImage.java:13) at FrameImage.main(FrameImage.java:30)
thanks sir.. [ March 02, 2005: Message edited by: Cyrus Serrano ]
Joined: Jan 14, 2004
should the java program and the image file be located on the same folder, Or should i create a new subfolder then copy the image on that folder Either way is okay. The hardest part is to figure out how to get the image to display for the first time. The error indicates that the class loader could not find the image. You can add a System.out.println statement to check the url that the class loader is using to find the image, like this:
With the getResource method the image file needs to be on the classpath. Inside the same folder as your class files should be okay. You could also try constructing a full URL with a protocol of file:
although this can be tricky to get right. You just have to play around with it till you figure it out.
You can make up a small test application to experiment with this
Here's what I got when I ran it
As you can see the images folder is in the current directory (same as what you show in your last post). You can use the string printed to the console in the new URL constructor