Skip to Main Content

New to Java

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

problem with path of Toolkit.getDefaultToolkit().getImage()

807598Feb 12 2006 — edited Apr 23 2007
I've seen this code many times, but I cannot get it to work:
MediaTracker tracker;

tracker = new MediaTracker(this);

Image image = Toolkit.getDefaultToolkit().getImage("test.gif");
tracker.addImage(image, 0);

try{
            tracker.waitForID(0);
        } catch (Exception ex) {
            System.out.println(ex.getMessage());
        }
but this works:
MediaTracker tracker;

tracker = new MediaTracker(this);

Image image = Toolkit.getDefaultToolkit().getImage("C:/path to image/test.gif");
tracker.addImage(image, 0);

try{
            tracker.waitForID(0);
        } catch (Exception ex) {
            System.out.println(ex.getMessage());
        }
Why doesn't it load the gif when just a filename is present? I've got the image in the same directory as the .java file and as the .class file.

Thanks for any help,
Ryan
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on May 21 2007
Added on Feb 12 2006
8 comments
109 views