https://imgur.com/a/2UyKR8r
public class MainActivity extends AppCompatActivity {
int c,d;
float x,y,z,a;
EditText ed1,ed2;
TextView t1;
Button b1,b2,b3,b4;
public void add(View v){
ed1 = findViewById(R.id.editText);
ed2 = findViewById(R.id.editText2);
t1 = findViewById(R.id.textView);
b1 = findViewById(R.id.button);
b2 = findViewById(R.id.button2);
b3 = findViewById(R.id.button3);
b4 = findViewById(R.id.button4);
c = Integer.parseInt(ed1.getText().toString());
d = Integer.parseInt(ed2.getText().toString());
x = c + d;
t1.setText(String.valueOf(x));
}
public void sub(View v){
y = c-d;
t1.setText(String.valueOf(y));
}
public void mul(View v){
z = c*d;
t1.setText(String.valueOf(z));
}
public void div(View v){
a = c/d;
t1.setText(String.valueOf(a));
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
}
单击减法(子)、乘法、除法时应用程序崩溃。
但是如果我先做加法然后点击任何其他功能它会工作正常,这是第一次点击按钮时。检查图像。
心有法竹
函数式编程
相关分类