Skip to content Skip to sidebar Skip to footer

The Method Load(context, Int, Int) In The Type Soundpool Is Not Applicable, The Method Getsystemservice(string) Is Undefined

Note: I'm kind of a noob so dont really know what these errors mean. This is my class code: package ryan.test; import java.util.HashMap; import android.content.Context; import an

Solution 1:

You can't access system services in a non-activity class unless you pass in the applicationContext or activity. You need to do this code in your extends Activity class.

You need to include the context in your constructor in order to access services provided by the sound provider, or pass in the sound provider management object in order to access these objects.

The code should be trivial, just declare a SoundPool object in your class and pass it into the constructor.

Solution 2:

You need a Context to use those methods. getSystemService is a method of the Context instance, myActivity.getSystemService(). load() also expects you to pass in the Context instance (myActivity) as the first argument. It's not recommended that you keep a reference to the context outside of the main activity, so you should consider moving this logic back into the activity. Why are you trying to do this in a singleton? Play music in the background? Use a service.

Solution 3:

The method load needs an instance of a Context (i.e. an Activity or a Service). As your singleton does not have that instance, you need to first set an instance of Context, and only after that, call the load method, using that instance.

Hence, you cannot do this in your constructor.

Post a Comment for "The Method Load(context, Int, Int) In The Type Soundpool Is Not Applicable, The Method Getsystemservice(string) Is Undefined"