AdapterView.OnItemSelectedListener returns a NULL view

I have the following code:

public class OnboardingActivity extends BaseLoggedInActivity
    implements CountryPickerDialog.ICountryPickerDialogUsers, AdapterView.OnItemSelectedListener {
private Spinner _countryCodeSpinner;

.
.
.
    private void setupCountrySpinner() {
        List<String> sortedCountryCodeList = CountryData.getInstance().getSortedCountryCodes();
    ArrayAdapter<String> adapter = new ArrayAdapter<>(this,
            R.layout.country_code_spinner_item,
            sortedCountryCodeList);
    _countryCodeSpinner.setOnItemSelectedListener(this);
    _countryCodeSpinner.setAdapter(adapter);
    _countryCodeSpinner
            .setOnTouchListener(getCountryCodeSpinnerTouchListener(_countryCodeSpinner));
    int position = getDefaultCountryNamePosition();
    if (position >= 0) {
        _countryCodeSpinner.setSelection(position);
    }
}

.
.
.
@Override
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
    _logger.debug("Inside onItemSelected");
    view.setSelected(true);
}

I get a null pointer exception in the onItemSelected function above . Its return form is NULL. This trace, which I receive from one of the users, but I can not reproduce it myself. What could be the reason that onItemSelected is called with a NULL view?

thank

+4
source share

Source: https://habr.com/ru/post/1570296/


All Articles