Tool Kit Image loader
<p>i'm reading a book on java programming iv'e come to a part were i don't understand  it's loading a bit image or something here's the code</p>

<pre><code>Toolkit tk = Toolkit.getDefaultToolkit();
image = tk.getImage(getURL("castle.png"));
</code></pre>

<p>what is the get URl am i suppose to tell it where the image actually is or something?</p>

<p>how can it locate the image i get this error when i run it like it is -</p>

<pre><code>Uncaught error fetching image:
java.lang.NullPointerException
</code></pre>

<p>Here's the full code -</p>

<pre><code>package randomshapes;

import java.awt.*;
import java.util.*;
import javax.swing.*;
import java.net.*;

public class RandomShapes extends JFrame{

  private Image image;

  public static void main(String [] args){
    new RandomShapes();
  }

  public RandomShapes(){
    super("DrawImage");
    setSize(600,600);
    setVisible(true);
    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    Toolkit tk = Toolkit.getDefaultToolkit();
    image = tk.getImage(getURL("castle.png"));
  }

  private URL getURL(String filename){
    URL url = null;
    try{
      url = this.getClass().getResource(filename);
    } catch (Exception e){ }
    return url;
  }

  public void paint(Graphics g){
    Graphics2D g2d = (Graphics2D) g;
    g2d.setColor(Color.WHITE);
    g2d.fillRect(0, 0, getSize().width, getSize().height);
    g2d.drawImage(image, 0, 40, this);
  }
}
</code></pre>
