-2

i am making a game and i put some images on my ide/images folder but program gives null pointer exception error.my code for loading imageicon is like this

 ImageIcon ac=new ImageIcon(getClass().getResource("images/actor.jpg"));
 ImageIcon ac1=new ImageIcon(getClass().getResource("images/actor_shoot.jpg"));
    //some codes

Image n=ac.getImage();
 //some codes

i tried but couldn't find,whats your suggestions?thanks.

rena-c
  • 325
  • 2
  • 3
  • 12
  • possible duplicate of [Java in Eclipse: Where do I put files on the filesystem that I want to load using getResource? (e.g. images for an ImageIcon)](http://stackoverflow.com/questions/270197/java-in-eclipse-where-do-i-put-files-on-the-filesystem-that-i-want-to-load-usin) – Barett Jun 24 '15 at 17:04

3 Answers3

0

Try with an absolute path ? ("/images/actor.jpg") ?

Rom1
  • 3,167
  • 2
  • 22
  • 39
  • its my netbeans/images folder.cant i do that.? – rena-c Jan 01 '12 at 14:46
  • Well I believe the only rule is that your resources should be in your classpath. You probably want to include said resources in your generated jar file(s). – Rom1 Jan 01 '12 at 14:53
0

Is your folder /images resides in same diretory in which your class is?

i.e., is your class is also in /ide folder?

Asif
  • 4,980
  • 8
  • 38
  • 53
0
  • Check the path. Are the files really in the images folder?

  • Are they called what you say there are called?

  • Are they the right case, if you're on a case-sensitive file system (in other words that actor.jpg and ACTOR.JPG are two different files)?

  • Are the images a resource? (Also look here.)

  • Try doing step-by-step what is described here (NetBeans documentation).

Christian Neverdal
  • 5,655
  • 6
  • 38
  • 93