我有这段代码:
TypedArray mAllowedCountries = application.getResources().obtainTypedArray(R.array.allowed_countries);
for (int index = 0; index < mAllowedCountries.length(); index++) {
if(mAllowedCountries.getString(index) != null) {
if (mAllowedCountries.getString(index).toUpperCase().equals(addressComponentCountry.short_name.toUpperCase())) {
supported = true;
break;
}
}
}
我收到关于
的 Android Studio Lint 警告方法调用'toUpperCase'可能会产生 '显示java.lang.NullPointerException'
如何修复此问题以摆脱 Lint 警告?
答案 0 :(得分:1)
以下内容应删除 Lint 警告:
final String address = addressComponentCountry.short_name.toUpperCase();
String tempStr;
for (int index = 0; index < mAllowedCountries.length(); index++) {
tempStr = mAllowedCountries.getString(index);
if(tempStr != null && tempStr.toUpperCase().equals(address)) {
supported = true;
break;
}
}