views:

1833

answers:

1

Okay, so I've been trying to load a BufferedImage using this code:

URL url = this.getClass().getResource("test.png");
BufferedImage img = (BufferedImage) Toolkit.getDefaultToolkit().getImage(url);

This gives me a type cast error when I run it though, so how do I properly load a BufferedImage?

+5  A: 

Use ImageIO.read() instead:

BufferedImage img = ImageIO.read(url);
Zach Scrivena
That did the trick. Thank you very much.
William