I am working on a music player, but I keep on getting this error whenever I try to play a song
LogCat:
Attempt to invoke virtual method 'void android.media.MediaPlayer.start()' on a null object reference
at com.musicapp.android.musicapp.PlayingScreen.playSongs(PlayingScreen.java:119)
Code:
public void playSongs() {
if(PlayingScreen_List != null){
uri = Uri.parse(PlayingScreen_List.get(position).getPath());
}
if (mediaPlayer != null) {
mediaPlayer.stop();
mediaPlayer.release();
mediaPlayer = MediaPlayer.create(getApplicationContext(), uri);
} else {
mediaPlayer = MediaPlayer.create(getApplicationContext(), uri);
}
Toast.makeText(getApplicationContext(),String.valueOf(uri),Toast.LENGTH_SHORT).show();
119 mediaPlayer.start();
}
AND no, my uri is not null.....I did a TOAST and it showed me the path for every song I clicked on.....WELPP? :)
"PlayingScreen_List" is not null I did a toast...it looks like this [1]: https://i.stack.imgur.com/iU1jf.jpg