title: GetImage with JApplet
body: <p>I have the following runnable code:</p>
  
  <pre><code>import java.awt.Graphics;
  
  import javax.swing.ImageIcon;
  import javax.swing.JApplet;
  import javax.swing.JPanel;
  
  
  public class Main extends JApplet{
      public static Main instance;
      public static ImageIcon getImage(String fname){
          return new ImageIcon(instance.getImage(instance.getDocumentBase(),fname));
      }
      public void init(){
          instance = this;
          @SuppressWarnings("serial")
          JPanel p = new JPanel(){
              ImageIcon img = getImage("YES.png");
              public void paintComponent(Graphics g){
                  super.paintComponent(g);
                  if(img != null)
                  g.drawImage(img.getImage(),0,0,getWidth(),getHeight(),null);
              }
          };
          this.setContentPane(p);
      }
  }
  </code></pre>
  
  <p>When I run this in eclipse it works.  But when I run it on google chrome with the following html document:</p>
  
  <pre><code>&lt;html&gt;
  &lt;head&gt;
      &lt;title&gt;VResponse&lt;/title&gt;
      &lt;style type="text/css"&gt;
          body{
              background-color:white;
              padding:1%;
          }
      &lt;/style&gt;
  &lt;/head&gt;
  &lt;body&gt;
  &lt;div&gt;
  &lt;applet code="Main.class" width="800" height="600" /&gt;
  &lt;/div&gt;
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>I get the following null pointer exception.:</p>
  
  <pre><code>java.lang.NullPointerException
      at sun.awt.SunToolkit.getImageFromHash(Unknown Source)
      at sun.awt.SunToolkit.getImage(Unknown Source)
      at Main.getImage(Main.java:15)
      at Main$1.&lt;init&gt;(Main.java:21)
      at Main.init(Main.java:20)
      at com.sun.deploy.uitoolkit.impl.awt.AWTAppletAdapter.init(Unknown Source)
      at sun.plugin2.applet.Plugin2Manager$AppletExecutionRunnable.run(Unknown Source)
      at java.lang.Thread.run(Unknown Source)
  </code></pre>
  
  <p>How do I fix?</p>
  
  <p><a href="http://vickysoderlund.atspace.cc/" rel="nofollow">http://vickysoderlund.atspace.cc/</a>
  /---= webpage with errored japplet on it</p>
  
  <p>You should beable to download the entire folder here:
  <a href="https://drive.google.com/file/d/0B0ng1kJkou-lcUlmWk91bEVXX28/edit?usp=sharing" rel="nofollow">https://drive.google.com/file/d/0B0ng1kJkou-lcUlmWk91bEVXX28/edit?usp=sharing</a></p>
  
  <p>And SRC code is here:
  <a href="https://drive.google.com/file/d/0B0ng1kJkou-lYXRERWFnU1czX0k/edit?usp=sharing" rel="nofollow">https://drive.google.com/file/d/0B0ng1kJkou-lYXRERWFnU1czX0k/edit?usp=sharing</a></p>