Почему вот так работает:
public void onButtonClick (View v){
EditText el1 = (EditText)findViewById(R.id.Num1);
EditText el2 = (EditText)findViewById(R.id.Num2);
TextView resText = (TextView)findViewById(R.id.Result);
int num1 = Integer.parseInt(el1.getText().toString());
int num2 = Integer.parseInt(el2.getText().toString());
int resSum = num1 + num2;
resText.setText(Integer.toString(resSum));
}
А вот так нет
EditText el1 = (EditText)findViewById(R.id.Num1);
EditText el2 = (EditText)findViewById(R.id.Num2);
TextView resText = (TextView)findViewById(R.id.Result);
int num1 = Integer.parseInt(el1.getText().toString());
int num2 = Integer.parseInt(el2.getText().toString());
public void onButtonClick (View v){
int resSum = num1 + num2;
resText.setText(Integer.toString(resSum));
}
Где мой гениальный план пошёл не по плану?