Problems loading images (png) in browser

Hello.

I have a game running in Applet and it works fine with Applet Viewer. And it works fine when I run it in a browser from my own computer. But when I try to load the game over the Internet, some pictures won’t load. JPGs work fine, haven’t tried with GIFs, but PNGs won’t load at all.

I load the image like this:

image = ImageIO.read(new BufferedInputStream(ImageBase.class.getClassLoader().getResourceAsStream(name)));

I found out that there is a bug with read andBufferedInputStream should fix it. Well, it doesn’t fix it in this case. Any ideas?

Edit: I tried to load the images with getImage and mediatracker but the same problem occurs. It’s pretty odd… I’ve never had this problem before.

Are you sure the URL is correct?

Got a URL to the png so we can take a look?

Alternatively, have a look at the png yourself with tweakpng

There are many PNGs but here is an example: http://koti.mbnet.fi/johann/Code/java/Coloribrium/red.png. The URL is correct because all the images are in the same folder and JPGs work. And it works perfectly when running from my own computer (with browser and applet viewer). Only over the internet there is problems.

Maybe JAR could fix the problem? I’ve never used JAR so I guess it’s time to learn. But still, why doesn’t it work like that…

Edit: Doesn’t work in JAR either. Exactly the same problem. Still works from my own computer but not from the Internet.

Edit: I don’t know why I didn’t check this out earlier, but when I load the image it throws an exception which says “Width (-1) and height (-1) cannot be <= 0”… This is sooo strange.

Edit: And ofcourse, you could also try it. http://koti.mbnet.fi/johann/Code/java/Coloribrium/. If it works for you, you should see some diamonds or something on the screen.

That exception is often the result of a failed image load. Are you throwing exceptions during the load as well? If not, you should.

Problem solved! This was really a tough one. Who would have guessed that getResourceAsStream is case sensitive over the Internet but not on your own computer? I hope this topic will someday help someone else so that I didn’t suffer this for nothing. :stuck_out_tongue:

Mmm, makes sense that this would be the problem. I figured it was related to actually finding the image. Glad you figured it out!