Java: NullPointerException from class.getResource( … )

后端 未结 5 1873
北海茫月
北海茫月 2020-11-30 14:03

I was writing a small application and when I tried to create an ImageIcon I always got an exception. The exception was caused by this line of code:

prayerLev         


        
5条回答
  •  谎友^
    谎友^ (楼主)
    2020-11-30 14:26

    Old thread but since I bumped into a similar problem just now...

    I'm using Eclipse and I copied a file to the "resources" folder using system commands (cp). However, eclipse threw a NullPointerException because I didn't refresh the "resources" folder. So the file was there but Eclipse didn't see it.

    So in Eclipse: "Package Explorer" -> "resources" -> Mouse right click -> refresh. This fixed it for me.

提交回复
热议问题