title: Error in NullPointerException in android market on music files
body: <p>Here are the error trace from android:</p>
  
  <pre><code>java.lang.NullPointerException
  at com.bappy.cror.MultiMedia.playSong(MultiMedia.java:48)
  at com.bappy.cror.MultiMedia.play(MultiMedia.java:132)
  at com.bappy.cror.MainActivity$1.onClick(MainActivity.java:146)
  at android.view.View.performClick(View.java:2408)
  at android.view.View$PerformClick.run(View.java:8816)
  at android.os.Handler.handleCallback(Handler.java:587)
  at android.os.Handler.dispatchMessage(Handler.java:92)
  at android.os.Looper.loop(Looper.java:123)
  at android.app.ActivityThread.main(ActivityThread.java:4633)
  at java.lang.reflect.Method.invokeNative(Native Method)
  at java.lang.reflect.Method.invoke(Method.java:521)
  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:858)
  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
  at dalvik.system.NativeStart.main(Native Method)
  </code></pre>
  
  <p>Here is my code:</p>
  
  <pre><code>public class MultiMedia {
      private static MediaPlayer mediaPlayer;
      private static AudioManager am;
  
      public static int getCurrentPosition() {
          return mediaPlayer.getCurrentPosition();
      }
  
      public static int getDuration() {
          return mediaPlayer.getDuration();
      }
  
      public static int getMaxVolume() {
          return am.getStreamMaxVolume(AudioManager.STREAM_MUSIC);
      }
  
      public static int getVolume() {
          return am.getStreamVolume(AudioManager.STREAM_MUSIC);
      }
  
      public static boolean isPuase() {
          if (mediaPlayer != null) {
              return isPause;
          }
          return false;
      }
  
      public static boolean isStarting() {
          if (mediaPlayer != null) {
              return isStarting;
          }
          return false;
      }
  
      public static void playSong(Context con, int songPath) {
  
          mediaPlayer = new MediaPlayer();
          am = (AudioManager) con.getSystemService(Context.AUDIO_SERVICE);
          mediaPlayer = MediaPlayer.create(con, songPath);
          mediaPlayer.setLooping(false);
          mediaPlayer.start();
  
          mediaPlayer.setOnCompletionListener(new OnCompletionListener() {
  
              public void onCompletion(MediaPlayer arg0) {
  
                  destroy();
              }
  
          });
  
      }
  
      public static void seek(int msec) {
          if (mediaPlayer != null) {
  
              if (msec &gt;= getDuration()) {
                  msec = getDuration();
              } else if (msec &lt;= 0) {
                  msec = 0;
              }
              mediaPlayer.seekTo(msec);
          }
      }
  
      public static synchronized void setVolume(int index) {      
          am.setStreamVolume(AudioManager.STREAM_MUSIC, index, 0);
      }
  
      public static void updatePos(int currentPosition) {
          pos = currentPosition;
  
      }
  
      private int intVolume;
  
      public static boolean isPause = false, ismute = false;
  
      private static boolean isStarting = false;
  
      Context context;
  
      private static int pos = 0;
  
      public static void destroy() {
          if (mediaPlayer != null) {
              mediaPlayer.stop();
              mediaPlayer.release();
              mediaPlayer = null;
              isStarting = false;
  
          }
      }
  
      public static void pause() {
          if (mediaPlayer != null) {
              mediaPlayer.pause();
              isPause = true;
          }
      }
  
      public static void play(Context con, int resource) {
          if (!ismute) {
              if (mediaPlayer != null) {
                  mediaPlayer.start();
  
                  isPause = false;
                  isStarting = true;
              } else {
                  playSong(con, resource);
              }
          }
      }
  
      public static void stop() {
          if (mediaPlayer != null) {
              mediaPlayer.seekTo(0);
              mediaPlayer.pause();
          }
      }
  
      public MultiMedia(Context con) {
          this.context = con;
          am = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE);
          mediaPlayer = new MediaPlayer();
  
      }
  
      public boolean getMute() {
          return getVolume() == 0;
      }
  
      public String getSongName() {
          return "this is song name";
      }
  
      public void setMute(Boolean isOn) {
          if (mediaPlayer != null) {
              if (isOn) {
                  intVolume = getVolume();
                  am.setStreamMute(AudioManager.STREAM_MUSIC, true);
              } else {
                  am.setStreamMute(AudioManager.STREAM_MUSIC, false);
                  setVolume(intVolume);
              }
          }
      }
  
  }
  </code></pre>
  
  <p>Line 48 in this code is : mediaPlayer.setLooping(false);</p>
  
  <p>I tried to re-create this error on my device but cant. I dont understand why i am getting this error. I will appreciate if any senior member can guide me or help me figure this out. Thanks.</p>