I am working in an android studio project where I am trying to make a number system convertor app. I have used 2 EditTexts (Binary and Decimal). APP SCREENSHOT
Here I want that whenever user give a input to decimal EditText, its corresponding value should be set in the binary EditText and vice-versa. I have used TextWatcher in each of the EdtTexts to calculate whenever user changes the value in the input fields. But I am having an issue that when the app crashes whenever something is input to any of the EditTexts.
TextWatcher used for decimal EditText:-
TextWatcher textDec=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) {
String binValue;
String decString;
decString = dec.getText().toString();
if (decString.trim().equals("")) {
binValue = "";
}
else {
binValue = decToBinMain(decString);
}
if (bin.getText().toString()!=binValue) {
textView4.setText(binValue);
bin.setText(binValue);
}
}
};
dec.addTextChangedListener(textDec);
Textwatcher used for binary EditText:-
TextWatcher textBin=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) {
String binValue;
String decString;
binValue=bin.getText().toString();
if(binValue.trim().equals("")){
decString="";
}
else {
decString = String.valueOf(binToDec(binValue));
}
if(!dec.getText().toString().equals(decString)) {
textView.setText(decString);
dec.setText(decString);
}
}
@Override
public void afterTextChanged(Editable s) {
}
};
bin.addTextChangedListener(textBin);
I have no Idea what is the issue and why the app crashes on input to any of the field. However, when I set the corresponding values to a textView, it does work perfectly. Any help would be aprpreciated!! ThankYou!!