I am trying to get my first app running on Android studio. The app instantiates and runs the setOnClickListener.
When I try to enter input for the addTextChangeListener it crashes.
"I have stripped back the code, to find where the fault is, but I still can't figure it out. I am new at this, being my first app.
outputText = (TextView) findViewById(R.id.outputText);
EditText ageText = (EditText) findViewById(R.id.userAge);
ageText.addTextChangedListener(new TextWatcher() {
@Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
}
@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
}
@Override
public void afterTextChanged(Editable s) {
int age = Integer.parseInt(userAge.getText().toString());
int intYears = Integer.valueOf(userYears.toString());
String text;
if (age < intYears/3){
text = getString(R.string.Message_1, userAge);
outputText.setText(text);
}
else{
text = getString(R.string.Message_2, userAge);
outputText.setText(text);
}
}
});
Expected: Enter an int m, convert int m to another int m' display m'. Enter int n in another text field, compare int n and m and display a text.
Result: Executes first part, app crashes when I try and enter int n in the other text field.