title: Android - play sound on button click - Null pointer exception
body: <p>I am trying to play a sound file on the click of a button. The sound is just 1 sec long. It plays well the first few times I click the button, but after a while it gives a <code>NullPointerException</code>. Here's the code:</p>
  
  <pre><code>button[i].setOnClickListener(new OnClickListener() {
      public void onClick(View view) {        
          mp = MediaPlayer.create(Test.this, R.raw.mysound);   
          mp.start();
      }
  });
  </code></pre>
  
  <p>And here's the exception:</p>
  
  <pre><code>07-29 23:07:27.690: ERROR/AndroidRuntime(10542): Uncaught handler: thread main exiting due to uncaught exception
  07-29 23:07:27.710: ERROR/AndroidRuntime(10542): java.lang.NullPointerException
  07-29 23:07:27.710: ERROR/AndroidRuntime(10542):     at com.example.mypackage.Test$3.onClick(Test.java:270)
  </code></pre>