public class MainActivity extends ActionBarActivity {
private EditText first;
private EditText second;
private TextView result;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
first =(EditText) findViewById(R.id.first);
second=(EditText) findViewById(R.id.second);
result=(TextView) findViewById(R.id.result);
first.addTextChangedListener(textwatcher);
second.addTextChangedListener(textwatcher);
}
private TextWatcher textwatcher =new TextWatcher() {
int f=Integer.parseInt(first.getText().toString());
int s=Integer.parseInt(second.getText().toString());
@Override
public void afterTextChanged(Editable arg0) {
// TODO Auto-generated method stub
result.setText(f+s);
}
@Override
public void beforeTextChanged(CharSequence arg0, int arg1, int arg2,
int arg3) {
// TODO Auto-generated method stub
}
@Override
public void onTextChanged(CharSequence arg0, int arg1, int arg2,
int arg3) {
// TODO Auto-generated method stub
}
};
为什么编译时没有显示错误 但运行在模拟器上确程序出错停止运行了呢(XML文件是对的)