I'm using Syncfusion.SfPicker for Xamarin.Android (https://help.syncfusion.com/xamarin-android/sfpicker/gettingstarted) and I'm using the latest version of the Syncfusion Nuget Library that contains the SfPicker.
My issue is that I receive the following error:
Object reference not set to an instance of an object, at Com.Syncfusion.SfPicker.SfPicker.UpdatePopup() [0x000d5] in :0 at Com.Syncfusion.SfPicker.SfPicker.set_IsOpen(System.Boolean value) [0x00018] in <4cccb4f208d9407ca543d91156e77529>:0 at MyTest_App.MainActivity.
When I execute following code in my MainActivity:
protected override void OnCreate(Bundle savedInstanceState)
{
SfPicker picker = new SfPicker(this);
base.OnCreate(savedInstanceState);
picker.IsOpen = true;
SetContentView(picker);
}
Is the documentation wrong/missing stuff, or am I simply doing it wrong? I followed the code from the last example of the URL I linked above.
Hopefully someone can shine some light on what's the issue is.
Is the documentation wrong/missing stuff, or am I simply doing it wrong? I followed the code from the last example of the URL I linked above.
You could refer to the Syncfusion Official Sample link, to avoid this exception, you must give your SfPicker
a ItemsSource
.
For example, create a ColorInfo
class :
public class ColorInfo
{
private ObservableCollection<string> _color;
public ObservableCollection<string> Colors
{
get { return _color; }
set { _color = value; }
}
public ColorInfo()
{
Colors = new ObservableCollection<string>();
Colors.Add("Red");
Colors.Add("White");
Colors.Add("Orange");
Colors.Add("Blue");
Colors.Add("Purple");
Colors.Add("Pink");
Colors.Add("SkyBlue");
Colors.Add("Yellow");
}
}
Set ItemSource
for your SfPicker
:
SfPicker picker;
protected override void OnCreate(Bundle savedInstanceState)
{
picker = new SfPicker(this);
base.OnCreate(savedInstanceState);
ColorInfo info = new ColorInfo();
picker.ItemsSource = info.Colors;
picker.IsOpen = true;
SetContentView(picker);
}