1 Reply Latest reply on Oct 28, 2007 6:11 AM by super_faz

    NetBeans IDE: Classpath not working for a JLabel icon image

    victorj42

      Hi all,

      I get an error after using NetBeans to select an image file for a JLabel icon.

      IDE code that works:
      gallows.setIcon(new javax.swing.ImageIcon("K:\\Hangman\\images\\gallows.gif"));

      IDE code that fails when I run the project:
      gallows.setIcon(new javax.swing.ImageIcon(getClass().getResource("/gallows.gif")));

      How I'm selecting the image location:
      1) from the IDE click the [...] next to the icon property of my label then choose classpath and click [select file].
      2) I am able to navigate to the file correctly and it is displayed in the preview window. I can even see it when I click on the test form button.

      If I run my file I get an error:
      netbeans Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
      at javax.swing.ImageIcon.(ImageIcon.java:138)
      at Keyboard.initComponents(Keyboard.java:175)
      at Keyboard.(Keyboard.java:15)
      <following errors removed by me>

      I hope someone can help me

      Thanks