我现在正在制作一个应用程序,它根据我按下的按钮播放声音,问题是我有 100 个按钮和 100 种不同的声音,过了一会儿它会破坏内存并崩溃给我 (-19,0) 错误是我的代码,你能告诉我如何避免这种情况吗?谢谢
package com.example.buttonsdemo;
import android.media.MediaPlayer;
import android.os.Bundle;
import android.app.Activity;
import android.support.v4.widget.SimpleCursorAdapter.ViewBinder;
import android.util.Log;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.Toast;
public class MainActivity extends Activity implements View.OnClickListener{
//Creating Sound arrays
MediaPlayer[] mediaplayer = new MediaPlayer[200];
int i = 0;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
//Creating Button Array
Button button[] = new Button [200];
mediaplayer[1]= MediaPlayer.create(this,R.raw.alistar);
mediaplayer[0]= MediaPlayer.create(this,R.raw.akali);
button[i].setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
switch(v.getId())
{
case R.id.akali:
i=0;
break;
case R.id.alistar:
i=1;
break;
}
mediaplayer[1].start();
}
} );
}
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
}
}
编辑:我试图让它更通用,所以我只调用 1 .start();