注: 私は初心者なので、これらのエラーの意味がよくわかりません。
これは私のクラスコードです:
package ryan.test;
import java.util.HashMap;
import android.content.Context;
import android.media.AudioManager;
import android.media.SoundPool;
public class MySingleton {
private MySingleton instance;
private static SoundPool mSoundPool;
private HashMap<Integer, Integer> soundPoolMap;
public static final int A1 = 1;
private MySingleton() {
mSoundPool = new SoundPool(5, AudioManager.STREAM_MUSIC, 0);// Just an example
soundPoolMap = new HashMap<Integer, Integer>();
soundPoolMap.put(A1, mSoundPool.load(this, R.raw.a, 1));
// soundPoolMap.put(A5, mSoundPool.load(MyApp.this, R.raw.a, 1));
}
public synchronized MySingleton getInstance() {
if(instance == null) {
instance = new MySingleton();
}
return instance;
}
public void playSound(int sound) {
AudioManager mgr = (AudioManager)MySingleton.getSystemService(Context.AUDIO_SERVICE);
float streamVolumeCurrent = mgr.getStreamVolume(AudioManager.STREAM_MUSIC);
float streamVolumeMax = mgr.getStreamMaxVolume(AudioManager.STREAM_MUSIC);
float volume = streamVolumeCurrent / streamVolumeMax;
mSoundPool.play(soundPoolMap.get(sound), volume, volume, 1, 0, 1f);
}
public SoundPool getSoundPool() {
return mSoundPool;
}
}
そして、2 つのエラーが発生しています。最初のエラーは次のとおりです。
soundPoolMap.put(A1, mSoundPool.load(this, R.raw.a, 1));
エラーには次のようThe method load(Context, int, int) in the type SoundPool is not applicable for the arguments (MySingleton, int, int)
に表示され、2番目のエラーは次のとおりです。
AudioManager mgr = (AudioManager)MySingleton.getSystemService(Context.AUDIO_SERVICE);
そしてエラーは言うThe method getSystemService(String) is undefined for the type MySingleton