1

I followed many guides about the music player, but my problem is the create method because when i try to do start() the activity crash saying to me that musicplayer is null, here is the code:

MediaPlayer mediaPlayer;
mediaPlayer = MediaPlayer.create(CustomMediaPlayer.this, R.raw.aud_0101);
...
mediaPlayer.start();

the audio file is right inside the raw directory, so I don't know how could be the problem of this nullPointer, anyone have some idea?

Daniel
  • 53
  • 1
  • 7
  • Possible duplicate of [What is a Null Pointer Exception, and how do I fix it?](http://stackoverflow.com/questions/218384/what-is-a-null-pointer-exception-and-how-do-i-fix-it) – ΦXocę 웃 Пepeúpa ツ Jan 19 '16 at 15:52
  • 1
    The audio file might be of the [wrong format](http://developer.android.com/guide/appendix/media-formats.html) – OneCricketeer Jan 19 '16 at 15:59
  • no, all files are in .mp3 format – Daniel Jan 19 '16 at 17:02
  • According to http://developer.android.com/reference/android/media/MediaPlayer.html#create(android.content.Context, android.net.Uri, android.view.SurfaceHolder, android.media.AudioAttributes, int) create returns null on failure. So probably the file is in wrong format. Try to see the logs, maybe you'll see some information that helps – Gavriel Jan 19 '16 at 17:09
  • Can you add the full trace of the crash? – Gavriel Jan 26 '16 at 22:02

0 Answers0