0

I'm trying to load an image using ImageIcon and Java keeps giving a NullPointerException on this line no matter how I format the file path:

ImageIcon ii = new ImageIcon(this.getClass().getResource("/img/icons/options.gif"));

Any help will be greatly appreciated, thanks!

Andrew Thompson
  • 168,117
  • 40
  • 217
  • 433

2 Answers2

0

Try removing the leading slash from your path of the image in getResouce call

getResource("img/icons/options.gif")

Path to image is relative to "your class.java"

lviggiani
  • 5,824
  • 12
  • 56
  • 89
0

In your NullPointerException error stack trace it would have given you the line number. In that line some value could be null hence this error. Try to check each value. You could debug using eclipse, or try to print the value using System.out.println and check. The reason could be in some other line which you have not given.

Jay
  • 9,189
  • 12
  • 56
  • 96