和老师的代码一模一样结果还是闪退运行不了?看了快一天了
public class MainActivity extends Activity implements OnClickListener{
EditText et;
Button bt0;
Button bt1;
Button bt2;
Button bt3;
Button bt4;
Button bt5;
Button bt6;
Button bt7;
Button bt8;
Button bt9;
Button btplus;
Button btmin;
Button btmul;
Button btdiv;
Button btpoint;
Button btclear;
Button btdel;
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
bt0=(Button) findViewById(R.id.button0);
bt1=(Button) findViewById(R.id.button1);
bt2=(Button) findViewById(R.id.button2);
bt3=(Button) findViewById(R.id.button3);
bt4=(Button) findViewById(R.id.button4);
bt5=(Button) findViewById(R.id.button5);
bt6=(Button) findViewById(R.id.button6);
bt7=(Button) findViewById(R.id.button7);
bt8=(Button) findViewById(R.id.button8);
bt9=(Button) findViewById(R.id.button9);
btplus=(Button) findViewById(R.id.buttonplu);
btmin=(Button) findViewById(R.id.buttonmin);
btdiv=(Button) findViewById(R.id.buttondiv);
btpoint=(Button) findViewById(R.id.buttondot);
btclear=(Button) findViewById(R.id.buttonc);
btdel=(Button) findViewById(R.id.buttondel);
et=(EditText) findViewById(R.id.edittext);
bt0.setOnClickListener(this);
bt1.setOnClickListener(this);
bt2.setOnClickListener(this);
bt3.setOnClickListener(this);
bt4.setOnClickListener(this);
bt5.setOnClickListener(this);
bt6.setOnClickListener(this);
bt7.setOnClickListener(this);
bt8.setOnClickListener(this);
bt9.setOnClickListener(this);
btplus.setOnClickListener(this);
btmin.setOnClickListener(this);
btmul.setOnClickListener(this);
btdiv.setOnClickListener(this);
btclear.setOnClickListener(this);
btdel.setOnClickListener(this);
btpoint.setOnClickListener(this);
}
@Override
public void onClick(View v) {
String str=et.getText().toString();//取现实屏上的内容
switch (v.getId()) {
case R.id.button0:
case R.id.button1:
case R.id.button2:
case R.id.button3:
case R.id.button4:
case R.id.button5:
case R.id.button6:
case R.id.button7:
case R.id.button8:
case R.id.button9:
case R.id.buttondot:et.setText(str+((Button)v).getText());break;
case R.id.buttonplu:
case R.id.buttonmin:
case R.id.buttonmul:
case R.id.buttondiv:et.setText(str+" "+((Button)v).getText()+" ");break;
case R.id.buttonc:et.setText("");break;
case R.id.buttondel:
if(str!=null&&!str.equals(""))
{
et.setText(str.subSequence(0, str.length()-1));
};break;
case R.id.buttonequal:
break;
}
}
}