首页 > 解决方案 > viewList itemSource 中的 System.NullReferenceException

问题描述

按照本教程:https ://docs.microsoft.com/pl-pl/xamarin/xamarin-forms/user-interface/listview/data-and-databinding

我得到了这个例外:

System.NullReferenceException:“对象引用未设置为对象的实例。”

在行:CategoryListView.ItemsSource = _category;

在教程中有一个警告,我猜这与我的问题有关,但我仍然不知道如何解决这个问题(我不完全理解警告)

命名空间 EduApp { [XamlCompilation(XamlCompilationOptions.Compile)] 公共部分类 QUIZListViewPage : ContentPage

{
   ObservableCollection<Category> _category = new ObservableCollection<Category>();
    //public ObservableCollection<Category> _Category { get { return _category; } }


    public QUIZListViewPage()

    {


        CategoryListView.ItemsSource = _category;

        _category.Add(new Category { categoryName = "first" });


        InitializeComponent();
    }
}

}

高级 C 中的 TY:

标签: xamarin.forms

解决方案


推荐阅读