2016-08-24 82 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()'方法 –