title: NullPointer when playing sound on Java
body: <p>I'm getting an error when trying to play sound. I'm getting a null pointer exception for some reason. The location and file I'm using both exsist, and when outputting the file string I do get the correct path to the file. The nullpointer is on the .open line. What am I doing wrong?</p>
  
  <pre><code>package main;
  
  import java.io.File;
  import java.io.IOException;
  import java.net.URL;
  
  import javax.sound.sampled.AudioSystem;
  import javax.sound.sampled.Clip;
  import javax.sound.sampled.LineUnavailableException;
  import javax.sound.sampled.UnsupportedAudioFileException;
  
  public class Sound {
      Clip background;
  
      public void init() {
  
      try {
          String file = new File("").getAbsolutePath() + "\\Sounds\\Pacman_Opening.wav";
          System.out.println(file);
          background = AudioSystem.getClip();
          background.open(AudioSystem.getAudioInputStream(getClass().getResource(file)));
      } catch (LineUnavailableException e) {
          // TODO Auto-generated catch block
          e.printStackTrace();
      } catch (IOException e) {
          // TODO Auto-generated catch block
          e.printStackTrace();
      } catch (UnsupportedAudioFileException e) {
          // TODO Auto-generated catch block
          e.printStackTrace();
      }
      }
  
      public void playBG() {
          background.start();
      }
      public void stopBG() {
          background.stop();
      }   
      public static void main(String[] args) {
          Sound s = new Sound();
          s.init();
          s.playBG();
      }
  
  }
  </code></pre>
  
  <p>This is the error (the first line is the location):</p>
  
  <pre><code>Exception in thread "main" java.lang.NullPointerException
      at com.sun.media.sound.WaveFileReader.getAudioInputStream(Unknown Source)
      at javax.sound.sampled.AudioSystem.getAudioInputStream(Unknown Source)
      at main.Sound.init(Sound.java:21)
      at main.Sound.main(Sound.java:42)
  </code></pre>