我是android开发的新手,正在尝试开发一个简单的应用程序,其中一个按钮用于播放声音。我正在尝试使用SoundPool,并且发现每个教程都给出了在创建soundpool对象之后要添加的代码:
soundPool.setOnLoadCompleteListener(new OnLoadCompleteListener() {
@Override
public void onLoadComplete(SoundPool soundPool, int sampleId,
int status) {
loaded = true;
}
});但是当我尝试在eclipse中使用这段代码时,它会说
类型为new SoundPool.OnLoadCompleteListener(){}的方法onLoadComplete(SoundPool,int,int)必须重写超类方法。并建议删除@override符号。如果没有这样的方法,应该会发生这种情况?为什么我会得到这个错误?
当我把soundID = soundPool.load(this,R.raw.mysound,1);
在上面的代码之后,eclipse声明类型SoundPool中的方法load(Context,int,int)不适用于参数(new View.OnClickListener(){},int,int)
这是我的整个代码:公共类FirstActivity扩展了Activity {在第一次创建activity时调用的/**。*/
private SoundPool soundPool;
int soundID;
boolean loaded = false;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Button bPlay = (Button) findViewById(R.id.bPlay);
final TextView aRing = (TextView)findViewById(R.id.tAlarmRinging);
bPlay.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
// TODO Auto-generated method stub
aRing.setVisibility(View.VISIBLE);
soundPool.setOnLoadCompleteListener(new OnLoadCompleteListener() {
@Override
public void onLoadComplete(SoundPool soundPool, int sampleId,
int status) {
loaded = true;
}
});
soundID = soundPool.load(this, R.raw.mysound, 1);
}
});
}}
发布于 2012-06-29 20:23:17
您应该尝试将项目遵从性级别设置为java 1.7或类似以下内容。
右键单击项目,转到Properties->Java compiler ->选中Enable project specific settings->然后选择最高的编译器遵从性级别。
如果这不起作用,那么右键单击项目,AndroidTools->Fix project properties。
https://stackoverflow.com/questions/11261526
复制相似问题