i have created a music app.the app has 16 music btns.the app is running with no problem but as i press the btns many times the app forces down..
super.onCreate(icicle);
setContentView(R.layout.main);
int[] ids = {R.id.btn,R.id.btn2, R.id.btn3, R.id.btn4, R.id.btn5, R.id.btn6, R.id.btn7, R.id.btn8, R.id.btn9, R.id.btn10,
R.id.btn11, R.id.btn12, R.id.btn13, R.id.btn14, R.id.btn15, R.id.btn16 };
for (int i : ids) {
b = (Button) findViewById(i);
b.setOnClickListener(this);
}}
//outside of onCreate()
@Override
public void onClick(View v) {
switch(v.getId()) {
case R.id.btn:
if (mp != null && mp.isPlaying()) mp.stop();
mp = MediaPlayer.create(zoo.this, R.raw.gata);
mp.start();
break;
this is the code and i use case for every btn.When the app forces down, the logCat is finding a NullPointerException in the mp.start(); of the button that forces the app down..please help!
EDIT in from comment below:
case R.id.btn:
if (mp != null && mp.isPlaying()) mp.stop();
mp.reset();
try {
mp.setDataSource("zoo.this,R.raw.gata");
} catch (IllegalArgumentException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
} catch (IllegalStateException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
} catch (IOException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
mp.start();
break;
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…