微调框返回null
问题描述:
countryCodeSpinner
在下面的代码片段中显示为null
。微调框返回null
countryCodeSpinner = (Spinner) findViewById(R.id.spinner_country);
countryCodeSpinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView<?> parentView, View selectedItemView, int position, long id) {
selectedCountryCode = (Long) selectedItemView.findViewById(R.id.country_name).getTag();
}
答
检查在初始化微调器之前是否已经放置了'setContentView()'方法。资源ID也可能与您在同一个布局文件中使用的资源ID不同。
+0
tnx pavan,我明白了这个问题在初始化微调器之前没有放置'setContentView()'方法 –
代码遍布全球,请更正。并为代码添加一些上下文。 – iMan
也许你的布局中没有R.id.spinner_country的资源。 请确保您选择了正确的布局 – Adnan
@avinash tiwari refere [this](http://*.com/help/how-to-ask)befor提问 – Nikhil