0

I am trying to make a music player for Android. The problem is that as soon as I open the app and press the play button it gives me an error

playPauseBtn.setOnClickListener(v -> {
    if (musicService != null){
      musicService.playPauseBtnClicked();
      if (musicService != null && musicService.isPlaying()){
         playPauseBtn.setImageResource(R.drawable.ic_pause);
      }else if (musicService != null){
         playPauseBtn.setImageResource(R.drawable.ic_play);
      }
     }
    });

Error:

java.lang.NullPointerException: Attempt to invoke virtual method 'boolean android.media.MediaPlayer.isPlaying()' on a null object reference
    at com.example.musix.MusicService.isPlaying(MusicService.java:105)
    at com.example.musix.NowPlayingFragmentBottom.lambda$onCreateView$1$com-example-musix-NowPlayingFragmentBottom(NowPlayingFragmentBottom.java:94)
    at com.example.musix.NowPlayingFragmentBottom$$ExternalSyntheticLambda1.onClick(Unknown Source:2)

0 Answers0