跟老師的一模一樣,但是使用this指針提示錯誤,麻煩大神解決一下
package com.example.calculate;
import android.app.Activity;
import android.content.DialogInterface;
import android.content.DialogInterface.OnClickListener;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.Button;
import android.widget.EditText;
public class MainActivity ?extends Activity implements OnClickListener{
? ? Button bt1;
? ? Button bt2;
? ? Button bt3;
? ? Button bt4;
? ? Button bt5;
? ? Button bt6;
? ? Button bt7;
? ? Button bt8;
? ? Button bt9;
? ? Button point;
? ? Button add;
? ? Button mulp;
? ? Button minus;
? ? Button divide;
? ? Button clear;
? ? Button delete;
? ? Button bt0;
? ? Button equal;
? ? EditText windows;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity2);
bt0=(Button) findViewById(R.id.bt0);
bt1=(Button) findViewById(R.id.bt1);
bt2=(Button) findViewById(R.id.bt2);
bt3=(Button) findViewById(R.id.bt3);
bt4=(Button) findViewById(R.id.bt4);
bt5=(Button) findViewById(R.id.bt5);
bt6=(Button) findViewById(R.id.bt6);
bt7=(Button) findViewById(R.id.bt7);
bt8=(Button) findViewById(R.id.bt8);
bt9=(Button) findViewById(R.id.bt9);
point=(Button) findViewById(R.id.point);
equal=(Button) findViewById(R.id.equal);
add=(Button) findViewById(R.id.add);
minus=(Button) findViewById(R.id.minus);
mulp=(Button) findViewById(R.id.mulp);
divide=(Button) findViewById(R.id.divide);
windows=(EditText)findViewById(R.id.windows);
}
private void setOnClickListener(MainActivity mainActivity) {
// TODO Auto-generated method stub
bt0.setOnClickListener(this);
bt1.setOnClickListener(this);
bt2.setOnClickListener(this);
bt2.setOnClickListener(this);
point.setOnClickListener(this);
bt3.setOnClickListener(this);
bt4.setOnClickListener(this);
bt5.setOnClickListener(this);
bt6.setOnClickListener(this);
bt7.setOnClickListener(this);
bt8.setOnClickListener(this);
bt9.setOnClickListener(this);
add.setOnClickListener(this);
minus.setOnClickListener(this);
mulp.setOnClickListener((this);
divide.setOnClickListener(this);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
@Override
public void onClick(DialogInterface dialog, int which) {
// TODO Auto-generated method stub
}
}

2017-02-15
求采納!
2017-02-15
發現了,原來導錯包了