So I use this code:
ClassLoader classLoader = getClass().getClassLoader();
File audioFile = new File(classLoader.getResource("pop.wav").getFile());
AudioInputStream audioStream = AudioSystem.getAudioInputStream(audioFile);
AudioFormat format = audioStream.getFormat();
DataLine.Info info = new DataLine.Info(Clip.class, format);
Clip audioClip = (Clip) AudioSystem.getLine(info);
audioClip.open(audioStream);
audioClip.start();
But every time it gives me a NullPointerException.
The file (pop.wav) is inside src/res. But if a put it on my desktop and instead of classLoader.getResource("pop.wav").getFile()
I put C:/Users/gebruiker/Desktop/pop.wav
it works.