0

My project JavaBasic gets NullPointerException at this line :

url = this.getClass().getClassLoader().getResource("/JavaBasic/res/sfx_wing.wav");

I think my getResource method get problems and it's relevant to Classpath, how can I set it ? Thanks!

Matt Clark
  • 27,671
  • 19
  • 68
  • 123

1 Answers1

0

Put the file sfx_wing.wav at the at level of the package of class calling the url. This if the class calling the url is in the package stackoverflow, put the file at the same level as the stackoverflow.

my-java-project
  src
    stackoverflow
     ClassCallingUrl
    sfx_wing.wav

Then used this call.

url = this.getClass().getClassLoader().getResource("sfx_wing.wav");

OR

url =this.getClass().getResource("/sfx_wing.wav");

Much explanation can be found here.

Community
  • 1
  • 1
berrytchaks
  • 839
  • 10
  • 18