0

I have a structure like ths (using IntelliJ

enter image description here

When I try and access items in the resources folder I get a null pointer exception:

private Icon bishopB = new ImageIcon( getClass().getResource("icons/bishopb.gif") );

exception:

Exception in thread "main" java.lang.NullPointerException
    at java.desktop/javax.swing.ImageIcon.<init>(ImageIcon.java:217)
    at chess.GUI.<init>(GUI.java:21)
    at chess.ChessGame.<init>(ChessGame.java:14)
    at chess.ChessGame.main(ChessGame.java:28)

when debugging it seems to be looking for the resource chess/icons/bishopb.gif

Tino
  • 63
  • 4
  • 13

1 Answers1

-1

Use getClass().getClassLoader() if you want to use full paths staring from the resource roots.

Andrey
  • 15,144
  • 25
  • 91
  • 187