We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date

Getting an odd error with rotator datasource

Hello !| 

I am trying to use rotator in normal layout, but I am getting an odd error saying " NullReferenceException: Object reference not set to an instance of an object.
 " while I am setting the datasource ! 

here is a snippet of my code 

     List<Com.Syncfusion.Rotator.SfRotatorItem> images = new List<Com.Syncfusion.Rotator.SfRotatorItem>();
            List<int> imageID = new List<int>();
            Context context = this;

            Com.Syncfusion.Rotator.SfRotatorItem item;
            ImageView image;
            for (int i = 0; i < imageID.Count; i++)
                item = new Com.Syncfusion.Rotator.SfRotatorItem(context);
                image = new ImageView(context);
                item.Content = image;

            Com.Syncfusion.Rotator.SfRotator rotator = FindViewById<Com.Syncfusion.Rotator.SfRotator> (Resource.Id.imageRotator);

6 Replies

ME Mark Eric May 6, 2019 09:43 PM UTC

I am using this method as reference : 

MK Muneesh Kumar G Syncfusion Team May 7, 2019 10:24 AM UTC

Hi Mark Eric, 
Thanks for using Syncfusion products, 
We have analyzed your query and we would like to inform you that NullReferenceException occurs due to the control instance passing to SetContentView method. 
If you initialize the control in axml page, then we don’t need to pass the view to SetContentView method. You can resolve this problem by passing the axml page resource layout id itself as per the below code snippet. 
Code snippet: 
SfRotator rotator = FindViewById<SfRotator>(Resource.Id.sfRotator1); 
List<SfRotatorItem> rotatorItems = new List<SfRotatorItem>(); 
List<int> images = new List<int>(); 
for (int i = 0; i < images.Count; i++) 
    SfRotatorItem sfRotatorItem = new SfRotatorItem(this); 
    ImageView imageView = new ImageView(this); 
    sfRotatorItem.Content = imageView; 
rotator.DataSource = rotatorItems; 
We have created sample for your requirement. Please download the sample from below location. 
Please let us know if you have any queries.  
Muneesh Kumar G  

ME Mark Eric May 8, 2019 11:56 PM UTC

Thanks so much for your help, Would you let me know how I can make the image stretch to fix the whole rotator? !

ME Mark Eric May 9, 2019 02:45 AM UTC

Thanks , 
I already solved using 

MK Muneesh Kumar G Syncfusion Team May 9, 2019 05:26 AM UTC

Hi Mark Eric,  
Glad that the issue has been resolved and please get back to us if you need any other assistance.  
Muneesh Kumar G   

ME Mark Eric May 14, 2019 02:54 AM UTC

Thanks ! 

Live Chat Icon For mobile
Up arrow icon