CountryCodePickerProject
CountryCodePickerProject copied to clipboard
Fatal Exception: java.lang.NullPointerException getNameCode() on a null object reference
Fatal Exception: java.lang.NullPointerException Attempt to invoke virtual method 'java.lang.String com.hbb20.CCPCountry.getNameCode()' on a null object reference com.hbb20.CountryCodePicker.setCustomDefaultLanguage (CountryCodePicker.java:1064) com.hbb20.CountryCodePicker.changeDefaultLanguage (CountryCodePicker.java:1996)
Please add null check in selectedCCPCountry.
Any updates on this fix?
It should go away with 2.5.2? Is it still happening in 2.5.2?
Hi,
It isn't solved because you added null check in some other variable that wasn't null.
Null check should be in selectedCCPCountry
variable. You can then add a default value in the case it is null.
Right. I missed one variable in 2.5.1 but then after you pointed out, I put another check in https://github.com/hbb20/CountryCodePickerProject/pull/488 and released 2.5.2. If it's still happening, not sure what's wrong.
Ok #488 should solve the issue. So probably I'm still getting reports from old versions. I'll keep an eye on that.
Just checked crashlytics again and I have another user with 14 crashes with:
CountryCodePicker.java line 1650
com.hbb20.CountryCodePicker.getDefaultCountryNameCode
Fatal Exception: java.lang.NullPointerException
Attempt to read from field 'java.lang.String com.hbb20.CCPCountry.nameCode' on a null object reference
com.hbb20.CountryCodePicker.getDefaultCountryNameCode (CountryCodePicker.java:1650)
com.hbb20.CountryCodePicker.resetToDefaultCountry (CountryCodePicker.java:1657)
com.hbb20.CountryCodePicker.detectLocaleCountry (CountryCodePicker.java:2328)
public String getDefaultCountryNameCode() {
return getDefaultCountry().nameCode.toUpperCase();
}
I guess this function is returning null somehow. defaultCCPCountry
can be null sometimes in situations I can't explain...
private CCPCountry getDefaultCountry() {
return defaultCCPCountry;
}
Best solution would be to always have a default country in the defaultCCPCountry
instance variable, (maybe add a World country for this situations?) and check for null in this function, so it doesn't crash where it's called.
Thanks
Hi, Check out the pull request #489 to see if we can solve this.
Thanks.