我有以下代码:
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);
}
我在上述函数onItemSelected中遇到了空指针异常。它返回了一个NULL视图。这个错误信息是从用户那里接收到的,但我自己无法重现它。有什么可能导致onItemSelected被调用时带有NULL视图?
谢谢。
_countryCodeSpinner.setSelection(position);
这行代码,列表弹出窗口没有显示,因此没有视图存在...请提供该设备上的Android版本?(可能在API 11之前,spinner列表弹出窗口更像是对话框) - Selvin