title: Java Netbeans: Bufferedimage can't read input file
body: <p>I'm trying to make a class which sets an image as its variable and tells the main class what image it is, then the main class paints it. Basically have an amount of objects that print themselves while they exist. I achieved this using <code>ImageIcon</code> but <code>BufferedImage</code> seems better for drawing many images at a time or images that move and so on, so I'd like to avoid using <code>ImageIcon</code>. Main class:</p>
  
  <pre><code>package handBasket;
  
  import java.awt.*;
  import javax.swing.*;
  public class AppStarter  extends JPanel
  {
  static ImageDisplayerTest idt;
  public void paintComponent(Graphics g)
  {
      g.drawImage(idt.demoPann, 0, 0, null);
  }
  public static void main(String[] args)
  {        
      JFrame frame = new JFrame();
      frame.setSize(800,600);
      frame.getContentPane().add(new AppStarter());
      frame.setVisible(true);
      frame.setTitle("The Great Graphical Achievement");
      frame.setResizable(false);
      int w = frame.getSize().width;
      int h = frame.getSize().height;
      Dimension dim = Toolkit.getDefaultToolkit().getScreenSize();
      int x = (dim.width-w)/2;
      int y = (dim.height-h)/2;
      frame.setLocation(x,y);
      frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
      idt = new ImageDisplayerTest();
      System.out.println(idt.demoPann);
  }
  }
  </code></pre>
  
  <p>This all worked fine while the image was an <code>ImageIcon</code>. As for the object that has the image to be drawn, it creates a File, reads the filename in to that file and tries to pass that file to the <code>BufferedImage</code> but that's where I get the <code>NullPointerException</code> saying that it cannot read the file. Tried with multiple files and filetypes, no change.</p>
  
  <pre><code>package handBasket;
  
  import java.awt.image.BufferedImage;
  import java.io.File;
  import java.io.IOException;
  import javax.imageio.ImageIO;
  
  public class ImageDisplayerTest
  {
  BufferedImage demoPann;
  File loadThis;
  public ImageDisplayerTest()
          {
              loadThis = new File("hp_small.jpg");
              try 
              {
              demoPann = ImageIO.read(loadThis); 
              } 
              catch (IOException e) 
              {
              System.out.println("wtf");
              }
          }
  }
  </code></pre>
  
  <p>Any suggestions and advice appreciated.</p>
  
  <p>-----Edit:</p>
  
  <p>When doing printStackTrace() I get the following lines, note that some of these are displayed anyway so I'm not sure what printStackTrace() is supposed to do.</p>
  
  <p>As for folder structure, everything is in the src/handBasket folder which is in the folder that is contained by my projects folder.</p>
  
  <pre><code>run:
  javax.imageio.IIOException: Can't read input file!
      at javax.imageio.ImageIO.read(ImageIO.java:1301)
      at handBasket.ImageDisplayerTest.&lt;init&gt;(ImageDisplayerTest.java:17)
      at handBasket.AppStarter.main(AppStarter.java:31)
  Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
      at handBasket.AppStarter.paintComponent(AppStarter.java:12)
      at javax.swing.JComponent.paint(JComponent.java:1054)
      at javax.swing.JComponent.paintChildren(JComponent.java:887)
      at javax.swing.JComponent.paint(JComponent.java:1063)
      at javax.swing.JComponent.paintChildren(JComponent.java:887)
      at javax.swing.JComponent.paint(JComponent.java:1063)
      at javax.swing.JLayeredPane.paint(JLayeredPane.java:585)
      at javax.swing.JComponent.paintChildren(JComponent.java:887)
      at javax.swing.JComponent.paintToOffscreen(JComponent.java:5228)
      at javax.swing.RepaintManager$PaintManager.paintDoubleBuffered(RepaintManager.java:1482)
      at javax.swing.RepaintManager$PaintManager.paint(RepaintManager.java:1413)
      at javax.swing.RepaintManager.paint(RepaintManager.java:1206)
      at javax.swing.JComponent.paint(JComponent.java:1040)
      at java.awt.GraphicsCallback$PaintCallback.run(GraphicsCallback.java:39)
      at sun.awt.SunGraphicsCallback.runOneComponent(SunGraphicsCallback.java:78)
      at sun.awt.SunGraphicsCallback.runComponents(SunGraphicsCallback.java:115)
      at java.awt.Container.paint(Container.java:1967)
      at java.awt.Window.paint(Window.java:3877)
      at javax.swing.RepaintManager.paintDirtyRegions(RepaintManager.java:781)
      at javax.swing.RepaintManager.paintDirtyRegions(RepaintManager.java:728)
      at javax.swing.RepaintManager.prePaintDirtyRegions(RepaintManager.java:677)
      at javax.swing.RepaintManager.access$700(RepaintManager.java:59)
      at javax.swing.RepaintManager$ProcessingRunnable.run(RepaintManager.java:1621)
      at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:251)
      at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:721)
      at java.awt.EventQueue.access$200(EventQueue.java:103)
      at java.awt.EventQueue$3.run(EventQueue.java:682)
      at java.awt.EventQueue$3.run(EventQueue.java:680)
      at java.security.AccessController.doPrivileged(Native Method)
      at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:76)
      at java.awt.EventQueue.dispatchEvent(EventQueue.java:691)
      at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:242)
      at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:161)
      at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:150)
      at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:146)
      at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:138)
      at java.awt.EventDispatchThread.run(EventDispatchThread.java:91)
  BUILD SUCCESSFUL (total time: 15 seconds)
  </code></pre>