我是 android 新手,我创建了一个媒体播放器应用程序,但是每当我开始播放它时,它突然停止并出现错误,因为“不幸的是,你的应用程序停止了”。 我应该如何纠正我的应用程序?
请帮助我这里的代码:
package com.example.allah;
import java.util.ArrayList;
import android.app.Activity;
import android.media.MediaPlayer;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.ListView;
public class MainActivity extends Activity {
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); setContentView(R.layout.activity_main);
final ListView listview = (ListView) findViewById(R.id.listView1);
String[] values = new String[] { "Allah1", "Allah2" };
final ArrayList<String> list = new ArrayList<String>();
for (int i = 0; i < values.length; ++i) {
list.add(values[i]);
}
listview.setAdapter(new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, list));
listview.setOnItemClickListener(new AdapterView.OnItemClickListener() {
public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,
long arg3) {
myplaymethod();
}
});
}
public void myplaymethod(){
int myKey = 0;
View play_button = null;
switch (myKey) {
case 1:
MediaPlayer my = MediaPlayer.create(getBaseContext(), R.raw.allah1);
my.start();
play_button.setVisibility(View.GONE);
break;
case 2:
MediaPlayer ma = MediaPlayer.create(getBaseContext(), R.raw.allah2);
ma.start();
play_button.setVisibility(View.GONE);
break;
}
}