2016-08-24 78 views
0

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(); 

      } 
+0

代码遍布全球,请更正。并为代码添加一些上下文。 – iMan

+0

也许你的布局中没有R.id.spinner_country的资源。 请确保您选择了正确的布局 – Adnan

+0

@avinash tiwari refere [this](http://stackoverflow.com/help/how-to-ask)befor提问 – Nikhil

回答

1

检查在初始化微调器之前是否已经放置了'setContentView()'方法。资源ID也可能与您在同一个布局文件中使用的资源ID不同。

+0

tnx pavan,我明白了这个问题在初始化微调器之前没有放置'setContentView()'方法 –