I have this structure:
1) main activity:
public class mainActivity extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(new GameView(this));
}
2) game view
SoundPool sp;
int mySound = 0;
public class GameView extends SurfaceView implements SurfaceHolder.Callback {
public GameView(Context context) {
super(context);
sp = new SoundPool(2, AudioManager.STREAM_MUSIC, 0);
mySound = sp.load(this, R.raw.mysound, 1);
}
On line “mySound = sp.load(this, R.raw.mysound, 1);” it gives me error – “The method load(Context, int, int) in the type SoundPool is not applicable for the arguments (GameView, int, int)”. Guys, how can i fix it? When I use “extends Activity” it works ok, but in SurfaceView it doesn’t work. Help please.
Change your code to pass the context like so: