Call a non-static method from static inner class

Moosa

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

babis
MainActivity mc = new MainActivity();

Instantiating a new activity doesn't make any sense. Instead, you need to find the existing instance of MainActivity and call it's desired method.

Also, using an activity to play music isn't really a good idea. Consider using a service.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Call non static method from different non static class

From Java

Why can’t this static inner class call a non-static method on its outer class?

From Java

Cannot access a method call from non-static to non-static class/method

From Java

How to instantiate non static inner class within a static method?

From Dev

How to call non static method from main class

From Java

Workaround to accessing non-static member method from a static inner class

From Dev

Can't call constructor of inner class in a static context -- "non-static variable this cannot be referenced from a static context"

From

How to call non-static method from static method of same class?

From Java

Referencing non static variable from within static Inner Class

From Dev

call non static method from static method in android

From Dev

How to call a non-static method from a static function in a class in php

From Dev

Call non static method from another page

From Dev

PHP: is it possible to call a static class method from another static class?

From Dev

Call non-static method from static context

From Java

Constructor method reference for (non-static) inner class?

From Javascript

js call static method from class

From Dev

How to call static class method from a struct?

From Dev

Dynamically call static method on class from string

From Dev

Call a static method from other class in python

From Dev

Call to dialog from View class with static method

From Dev

Access method of private class inside static inner class from main()

From Dev

referencing the App context from a non-static inner class

From Java

Instantiating a non-static Java Inner Class from JRuby

From Dev

How can a non-static class call another non-static class's method?

From Java

Why can't we have static method in a (non-static) inner class?

From Java

Java: how to call non static method from main method?

From Java

Entity class and encapsulation confusion - how do you call a non-static method from main()?

From Dev

How to call a non static public method from a Singleton class which is using Google @Inject

From Dev

C# call non static method with different instance of a Class

Related Related

  1. 1

    Call non static method from different non static class

  2. 2

    Why can’t this static inner class call a non-static method on its outer class?

  3. 3

    Cannot access a method call from non-static to non-static class/method

  4. 4

    How to instantiate non static inner class within a static method?

  5. 5

    How to call non static method from main class

  6. 6

    Workaround to accessing non-static member method from a static inner class

  7. 7

    Can't call constructor of inner class in a static context -- "non-static variable this cannot be referenced from a static context"

  8. 8

    How to call non-static method from static method of same class?

  9. 9

    Referencing non static variable from within static Inner Class

  10. 10

    call non static method from static method in android

  11. 11

    How to call a non-static method from a static function in a class in php

  12. 12

    Call non static method from another page

  13. 13

    PHP: is it possible to call a static class method from another static class?

  14. 14

    Call non-static method from static context

  15. 15

    Constructor method reference for (non-static) inner class?

  16. 16

    js call static method from class

  17. 17

    How to call static class method from a struct?

  18. 18

    Dynamically call static method on class from string

  19. 19

    Call a static method from other class in python

  20. 20

    Call to dialog from View class with static method

  21. 21

    Access method of private class inside static inner class from main()

  22. 22

    referencing the App context from a non-static inner class

  23. 23

    Instantiating a non-static Java Inner Class from JRuby

  24. 24

    How can a non-static class call another non-static class's method?

  25. 25

    Why can't we have static method in a (non-static) inner class?

  26. 26

    Java: how to call non static method from main method?

  27. 27

    Entity class and encapsulation confusion - how do you call a non-static method from main()?

  28. 28

    How to call a non static public method from a Singleton class which is using Google @Inject

  29. 29

    C# call non static method with different instance of a Class

HotTag

Archive