Java – Call non-static methods from static inner classes

Call non-static methods from static inner classes… here is a solution to the problem.

Call non-static methods from static inner classes

I’m new to Android and I’m having this issue with nullPointerException when I call a non-static method from a static inner class, below is my code.

public void playPauseMusic() {
     check for already playing
    if (mp.isPlaying()) {
        if (mp != null) {
             Changing button image to play button
    } else {
         Resume surah
        if (mp != null) {
             Changing button image to pause button

public static class notifyPlayPauseListner extends BroadcastReceiver {
    public void onReceive(Context context, Intent intent) {

Log.i("PLAY/Pause Tag","In the listener Play/Pause  ");
        MainActivity mc = new MainActivity();

Probably a simple concept, but I’m new to android, that’s why I asked. Please help


MainActivity mc = new MainActivity();

There is no point in instantiating a new activity. Instead, you need to find an existing instance of MainActivity and call the methods it wants.

Also, using activities to play music is not a good idea. Consider using service

Related Problems and Solutions