<p>I'm using NetBeans, trying to change the familiar Java coffee cup icon to a png file that I have saved in a resources directory in the jar file.  I've found many different web pages that claim they have a solution, but so far none of them work.</p>

<p>Here's what I have at the moment (leaving out the try-catch block):</p>

<pre><code>URL url = new URL("com/xyz/resources/camera.png");
Toolkit kit = Toolkit.getDefaultToolkit();
Image img = kit.createImage(url);
getFrame().setIconImage(img);
</code></pre>

<p>The class that contains this code is in the <strong>com.xyz</strong> package, if that makes any difference.  That class also extends JFrame.  This code is throwing a MalformedUrlException on the first line.</p>

<p>Anyone have a solution that works?</p>

```
```
java.net.URL url = ClassLoader.getSystemResource("com/xyz/resources/camera.png");
```
```
May or may not require a '/' at the front of the path.