CountryCodePickerProject
CountryCodePickerProject copied to clipboard
NPE at !detectedCountry.equals(selectedCountry)
detectedCountry can be null. But in line !detectedCountry.equals(selectedCountry) we use it
@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
CCPCountry selectedCountry = getSelectedCountry();
if (selectedCountry != null && (lastCheckedNumber == null || !lastCheckedNumber.equals(s.toString())) && countryDetectionBasedOnAreaAllowed) {
//possible countries
if (currentCountryGroup != null) {
String enteredValue = getEditText_registeredCarrierNumber().getText().toString();
if (enteredValue.length() >= currentCountryGroup.areaCodeLength) {
String digitsValue = PhoneNumberUtil.normalizeDigitsOnly(enteredValue);
if (digitsValue.length() >= currentCountryGroup.areaCodeLength) {
String currentAreaCode = digitsValue.substring(0, currentCountryGroup.areaCodeLength);
if (!currentAreaCode.equals(lastCheckedAreaCode)) {
CCPCountry detectedCountry = currentCountryGroup.getCountryForAreaCode(context, getLanguageToApply(), currentAreaCode);
if (!detectedCountry.equals(selectedCountry)) {
countryChangedDueToAreaCode = true;
lastCursorPosition = Selection.getSelectionEnd(s);
setSelectedCountry(detectedCountry);
}
lastCheckedAreaCode = currentAreaCode;
}
}
}
}
lastCheckedNumber = s.toString();
}
}