-2
我想填充列表視圖。以下是代碼。我得到空指針異常。在調試時,我發現mListView爲空。我不確定爲什麼即使列表正確初始化,mListview也是null。空指針雖然小部件被正確初始化
public class MainActivity : Activity
{
private IndexableListView mListView;
protected override void OnCreate (Bundle bundle)
{
base.OnCreate (bundle);
SetContentView (Resource.Layout.Main);
List<string> mItems = new List<string>();
mItems.Add("Diary of a Wimpy Kid 6: Cabin Fever");
mItems.Add("Steve Jobs");
mItems.Add("Inheritance (The Inheritance Cycle)");
ContentAdapter adapter = new ContentAdapter(this, Android.Resource.Layout.SimpleListItem1, mItems);
mListView = (IndexableListView) FindViewById<ListView>(Resource.Id.listview);
mListView.Adapter = adapter;
上面的代碼中我設置適配器的最後一行 - 在那裏mListview是空的,並給我例外。任何幫助深表感謝。 PS:上面的代碼是用於Xamarin
如果你有一個* listview *作爲id的* IndexableListView *標籤,請檢查你的* Main.xml *。 – Rami
你能給我們XML嗎? –