I'm new to Android, I'm facing this problem that when I call a non-static method from static inner class I have nullPointerException, Below is my code.
public void playPauseMusic() {
// check for already playing
if (mp.isPlaying()) {
if (mp != null) {
mp.pause();
// Changing button image to play button
btnPlay.setImageResource(R.drawable.btn_play);
}
} else {
// Resume surah
if (mp != null) {
mp.start();
// Changing button image to pause button
btnPlay.setImageResource(R.drawable.btn_pause);
}
}
}
public static class notifyPlayPauseListner extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
Log.i("PLAY/Pause Tag","In the listener Play/Pause ");
MainActivity mc = new MainActivity();
mc.playPauseMusic();
}
}
May be its a simple concept but I'm new to android that's why asking. Kindly Help