Java client side gif loading problem

A

adrian.bartholomew

Hi. I have a server/client game solution that utilises many gifs in
the course of its life.
However, I have 3 gifs that are PRIORITY and should be loaded at the
start and for speed purposes, should be loaded directly from a local
client side folder.
So I placed them in a folder int the client path so that that floder
would be included in the client jar file.
On expanding the jar file, I have confirmed that the gif folder is
indeed in the package.
This is the code I'm using to load a gif from that folder:

URL url = getClass().getResource("../images_priority/" +
pi.index + ".gif");
image = ResourceUtils.getImage(url);


....
public static Image getImage(URL url) {
if (url == null) return null;
Image image = null;
try {
image = GraphicsUtilities.loadCompatibleImage(url);
} catch (IOException ex) {
ex.printStackTrace();
}
if (image != null && image.getWidth(null) > 0) {
System.out.println("Found the image file: " +
url.toString() + " : " +
image.getWidth(null) + "," +
image.getHeight(null));
}
else System.err.println("Couldn't find file: " +
url.toString());
return image;
}
_______________________


When I run the program from my IDE, everything loads fine.
However, it does not when run from a browser/remote server situation.

Any ideas?
 
M

Mark Space

URL url = getClass().getResource("../images_priority/" +


I wouldn't use ".." in a relative path... if I was a classloader, I'd
prevent this. Use an absolute path if the image is not in the same package.

Also, case matters. If your gif is named MY_FILE.GIF that lower case
".gif" probably won't work.

(Also, realize that a Java "package" is not a .jar file. Please use
correct terms, I think you are confusing yourself.)
} catch (IOException ex) {
ex.printStackTrace();
}
if (image != null && image.getWidth(null) > 0) {
System.out.println("Found the image file: " + ;
}
else System.err.println("Couldn't find file: " +
Any ideas?


Which of the above error messages do you see? What does it say?
 
A

adrian.bartholomew

I wouldn't use ".." in a relative path... if I was a classloader, I'd
prevent this. Use an absolute path if the image is not in the same package.

Also, case matters. If your gif is named MY_FILE.GIF that lower case
".gif" probably won't work.

(Also, realize that a Java "package" is not a .jar file. Please use
correct terms, I think you are confusing yourself.)




Which of the above error messages do you see? What does it say?

You are correct. "package" was the wrong word. But as I said, it WORKS
from my IDE. So neither case nor Classloader's treatment of ".../" can
be suspects.
I have not found a way to see Java error messages from any of my Mac
browsers. If you're willing and have the capability, kindly go to
http://all4s.net, register, sign in, hit the "PLAY NOW" text just
below the Submit button, click into any room and check your Java
errors window.

Thank much for taking the time to help me.
 
A

adrian.bartholomew

I wouldn't use ".." in a relative path... if I was a classloader, I'd
prevent this. Use an absolute path if the image is not in the same package.

Also, case matters. If your gif is named MY_FILE.GIF that lower case
".gif" probably won't work.

(Also, realize that a Java "package" is not a .jar file. Please use
correct terms, I think you are confusing yourself.)




Which of the above error messages do you see? What does it say?

Well......i have to concede ans say that your ARE right.
I used my applet class RoomClient for the url retrieval.
URL url = RoomClient.class.getResource("images_priority/" + pi.index +
".gif");

it works remotely just fine.
My apologies for doubting you.
 
M

Mark Space

Well......i have to concede ans say that your ARE right.
I used my applet class RoomClient for the url retrieval.
URL url = RoomClient.class.getResource("images_priority/" + pi.index +
".gif");

it works remotely just fine.
My apologies for doubting you.

I don't do applet programming but that's an issue we've seen a few times
on this list. Applets run in a different environment than what your IDE
does. Almost always it's a permission on the classloader when stuff
works in the IDE but not in the field.

I'd think about two things right now:

1. Setting up a better simulation of your target environment so you can
generate errors. Figure out how to run the IDE or appviewer with
permissions similar to the browser so you CAN see problems.

2. Figure out how to get those error messages from a client. I'd look
at logging them, not using println, and sending the log to the server.

As I say, I don't do applet programming, so I can't say how to do those
things, but in general it's needed in any environment. Underestimating
what is required for testing is very common in software engineering.
Once you've found a defect in your testing like this, it's best to stop
and figure out how to plug the test-hole right away, rather than waiting
until the same problem bites you again... and again... and again... etc.


Good luck.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,969
Messages
2,570,161
Members
46,710
Latest member
bernietqt

Latest Threads

Top