I had the same issue working on a project with Maven. Here how I fixed it: I just put the sources (images, musics and other stuffs) in the resources directory:
src/main/resources
I created the same structure for the packages in the resources directory too. For example:
If my class is on
com.package1.main
In the resources directory I put one package with the same name
com.package1.main
So I use
getClass().getResource("resource.png");