0

我的目標是將項目添加到動態微調器,我想這樣做在對話框(非活動類),但我得到這樣java.lang.NullPointerException: Attempt to invoke virtual method 'void android.widget.Spinner.setAdapter(android.widget.SpinnerAdapter)' on a null object reference的Android微調setAdapter()上的一個空對象引用異常

DisKapiList的例外是我的列表中包含用於添加到微調器的項目。

這是我的代碼;

spBBKapiNo = (Spinner)dialog.findViewById(UIUtils.getResourceId(wrapper.getmActiviy(), "spBBKapiNo", "id")); 

disKapList = yapi.getNumaratajList(); 
    List <SpinnerObject> lables = getAllLabels(); 
    ArrayAdapter<SpinnerObject> dataAdapter = new ArrayAdapter<SpinnerObject>(wrapper.getmActiviy(),android.R.layout.simple_spinner_dropdown_item, lables); 
    dataAdapter.setDropDownViewResource(UIUtils.getResourceId(wrapper.getmActiviy(), "spBBKapiNo", "id")); 
    spBBKapiNo.setAdapter(dataAdapter); 

getAllLabels()方法是;

public List <SpinnerObject> getAllLabels(){ 
    List <SpinnerObject> labels = new ArrayList <SpinnerObject>(); 

    for (Numarataj object : disKapList) { 
     labels.add (new SpinnerObject (object.getId() , object.getKapiNo())); 
    } 

    return labels; 
} 

Spinner field in my layout;

<Spinner 
       android:id="@+id/spBBKapiNo" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:entries="@array/empty_array" 
       android:layout_marginLeft="30dp" /> 

編輯;

現在我可以在dilaog上看到我的SpinnerList,但是當我使用微調來查看其他選項時,程序使用Resources $ NotFoundException關閉:資源ID#0x7f0f0069類型#0x12無效。

+0

請發佈您的佈局代碼和spBBKapiNo初始化。 – mol

回答

0

已解決!

List <SpinnerObject> lables = getAllLabels(); 
     ArrayAdapter<SpinnerObject> dataAdapter = new ArrayAdapter<SpinnerObject>(wrapper.getmActiviy(),android.R.layout.simple_spinner_dropdown_item, lables); 
     dataAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); 
     spBBKapiNo.setAdapter(dataAdapter); 
相關問題