Hey I want to load sounds on a soundPool inside a Thread which contains a sleep command. The block I am talking about looks like that:
Thread wait = new Thread() {
@Override
public void run() {
try {
sleep(800);
soundsMap.put(SOUND5, soundPool.load(this, R.raw.w5, 1));
} catch (InterruptedException e) {
// blub
} finally {
}
}
};
wait.start();
Eclipse marks an error at load
and writes:
The method
load(Context, int, int)
in the typeSoundPool
is not applicable for the arguments(new Thread(){}, int, int)
Has anyone an idea how I can solve this? I don't really understand what the message wants to tell me.
The three-argument form of SoundPool.load()
takes a Context
reference as an argument. Activity
extends Context
, so if you're writing code in an Activity
sub-class you can just use this
.
You're not doing that -- you're in a generic Thread
instance -- and the compiler is letting you know.
To fix this you'll need to reference your Activity
instance from your Runnable
class, and pass that as the first argument to load()
.