有人可以帮忙吗?我试图在一个活动上使用三个按钮,第一个按钮工作正常,但其他按钮没有,当我点击另一个按钮时,应用程序崩溃。我已经为主要活动附上了以下代码
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Button b1 = (Button) findViewById(R.id.bplayer1);
Button b2 = (Button) findViewById(R.id.bPlayer2);
TextView tvList = (TextView) findViewById(R.id.tvList);
b1.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent myIntent = new Intent(MainActivity.this, Player1Activity.class);
MainActivity.this.startActivity(myIntent);
}
});
b2.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent myIntent2 = new Intent(MainActivity.this, Player2Activity.class);
MainActivity.this.startActivity(myIntent2);
}
});
tvList.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent myIntent3 = new Intent(MainActivity.this, ListActivity.class);
MainActivity.this.startActivity(myIntent3);
}
});
}
}