SfTreeView gives NullReferenceException on Xamarin.Forms Android

On UWP everything is ok but on Android, SfTreeView throws null reference exception.


Model :
public class FoodSpecies : INotifyPropertyChanged
{
    private string _speciesName;
    private ObservableCollection<FoodSpecies> _species;

    public ObservableCollection<FoodSpecies> Species
    {
        get { return _species; }
        set
        {
            _species = value;
            RaisedOnPropertyChanged("Species");
        }
    }

    public string SpeciesName
    {
        get { return _speciesName; }
        set
        {
            _speciesName = value;
            RaisedOnPropertyChanged("SpeciesName");
        }
    }

    public event PropertyChangedEventHandler PropertyChanged;

    public void RaisedOnPropertyChanged(string _PropertyName)
    {
        if (PropertyChanged != null)
        {
            PropertyChanged(this, new PropertyChangedEventArgs(_PropertyName));
        }
    }
}

View :
<MasterDetailPage
    x:Class="TreeViewTest.MainPage"
    xmlns="http://xamarin.com/schemas/2014/forms"
    xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
    xmlns:treeView="clr-namespace:Syncfusion.XForms.TreeView;assembly=Syncfusion.SfTreeView.XForms"
    xmlns:viewModel="clr-namespace:TreeViewTest.ViewModel;assembly=TreeViewTest">

    <MasterDetailPage.BindingContext>
        <viewModel:FoodSpeciesViewModel />
    </MasterDetailPage.BindingContext>

    <MasterDetailPage.MasterBehavior>
        <MasterBehavior>Popover</MasterBehavior>
    </MasterDetailPage.MasterBehavior>

    <MasterDetailPage.Master>
        <ContentPage Title="Tree View Test">
            <StackLayout Spacing="0">
                <Label
                    FontSize="Large"
                    HorizontalOptions="Center"
                    Text="Hello World !"
                    VerticalOptions="Center" />
            </StackLayout>
        </ContentPage>
    </MasterDetailPage.Master>

    <MasterDetailPage.Detail>
        <ContentPage>
            <Grid Margin="0" RowSpacing="0">
                <Grid.RowDefinitions>
                    <RowDefinition Height="*" />
                </Grid.RowDefinitions>
                <treeView:SfTreeView
                    AutoExpandMode="AllNodesExpanded"
                    ChildPropertyName="Species"
                    ExpandActionTarget="Node"
                    ExpanderWidth="40"
                    Indentation="10"
                    ItemHeight="40"
                    ItemsSource="{Binding SpeciesType}">
                    <treeView:SfTreeView.ItemTemplate>
                        <DataTemplate>
                            <Grid Padding="5,0,0,0" BackgroundColor="Transparent">
                                <Label
                                    FontSize="Medium"
                                    Text="{Binding SpeciesName}"
                                    VerticalTextAlignment="Center" />
                            </Grid>
                        </DataTemplate>
                    </treeView:SfTreeView.ItemTemplate>
                </treeView:SfTreeView>
            </Grid>
        </ContentPage>
    </MasterDetailPage.Detail>

</MasterDetailPage>


View Model :
public class FoodSpeciesViewModel
{
    public ObservableCollection<FoodSpecies> SpeciesType { get; set; }

    public FoodSpeciesViewModel()
    {
        var fruit = new FoodSpecies { SpeciesName = "Fruits" };

        var oranges = new FoodSpecies { SpeciesName = "Oranges" };
        var pineapple = new FoodSpecies { SpeciesName = "Pineapple" };
        var apples = new FoodSpecies { SpeciesName = "Apples" };

        var apple = new FoodSpecies { SpeciesName = "Apple" };
        var macintosh = new FoodSpecies { SpeciesName = "Macintosh" };
        var grannysmith = new FoodSpecies { SpeciesName = "Granny Smith" };
        var fuji = new FoodSpecies { SpeciesName = "Fuji" };

        fruit.Species = new ObservableCollection<FoodSpecies>
        {
            oranges,
            pineapple,
            apples,
        };

        apples.Species = new ObservableCollection<FoodSpecies> { apple, macintosh, grannysmith, fuji };
        SpeciesType = new ObservableCollection<FoodSpecies> { fruit };
    }
}

3 Replies

JN Jayaleshwari N Syncfusion Team October 11, 2018 12:00 PM UTC

Hi Moien,  
 
Thanks for using Syncfusion products.  
 
We have checked the reported query from our end. We would like to let you know that the reported exception is already fixed in our side. The fix for this issue will be included in our 2018 Vol 3 SP1 which is scheduled to be rolled out by the end of October, 2018. Until then, you can use the below patch,   
 
 
The assemblies should be replaced with the existing assemblies in the following location.                 
{Syncfusion Installed location}\Essential Studio\16.3.0.21\Xamarin\lib\pcl\Syncfusion.SfTreeView.XForms.dll                                
{Syncfusion Installed location}\Essential Studio\16.3.0.21\Xamarin\lib\android\Syncfusion. SfTreeView.XForms.dll                             
{Syncfusion Installed location}\Essential Studio\16.3.0.21\Xamarin\lib\android\Syncfusion.SfTreeView.XForms.Android.dll                                                                                                                                           
{Syncfusion Installed location}\Essential Studio\16.3.0.21\Xamarin\lib\iOS\Syncfusion. SfTreeView.XForms.dll                             
{Syncfusion Installed location}\Essential Studio\16.3.0.21\Xamarin\lib\iOS\Syncfusion. SfTreeView.XForms.iOS.dll                     
{Syncfusion Installed location}\Essential Studio\16.3.0.21\Xamarin\lib\uwp\Syncfusion. SfTreeView.XForms.dll                             
{Syncfusion Installed location}\Essential Studio\16.3.0.21\Xamarin\lib\uwp\Syncfusion. SfTreeView.XForms.UWP.dll           
                       
Disclaimer: Please note that we have created these assemblies for the version 16.3.0.21 specifically to resolve the query requested in this forum 140323.  
 
If the issue still replicates, please share the stack trace when exception occurs which will help us to analyze the query better and provide appropriate solution at our end.  
      
Regards,  
Jayaleshwari N    



JI Jiri October 16, 2018 11:51 PM UTC

I am experiencing the same exception even with the patch libraries. Here is the stack trace:

[MonoDroid] UNHANDLED EXCEPTION:
[MonoDroid] System.NullReferenceException: Object reference not set to an instance of an object.
[MonoDroid]   at Syncfusion.Android.TreeView.ItemGenerator.UpdateNodeItem (Syncfusion.Android.TreeView.TreeViewItemInfoBase itemInfo, System.Int32 rowindex, Syncfusion.TreeView.Engine.TreeViewNode treeViewnode) [0x000c9] in <750c8951b0c04cf28c87bd3cd2791c19>:0 
[MonoDroid]   at Syncfusion.Android.TreeView.ItemGenerator.CreateNodeItem (System.Int32 rowindex, Syncfusion.TreeView.Engine.TreeViewNode treeViewNode) [0x00048] in <750c8951b0c04cf28c87bd3cd2791c19>:0 
[MonoDroid]   at Syncfusion.Android.TreeView.LayoutBase.CreateTreeViewItem (System.Int32 itemIndex, Syncfusion.XForms.TreeView.ItemType itemType, Syncfusion.TreeView.Engine.TreeViewNode itemData) [0x0000b] in <750c8951b0c04cf28c87bd3cd2791c19>:0 
[MonoDroid]   at Syncfusion.Android.TreeView.LinearLayout.EnsureItems (Syncfusion.GridCommon.ScrollAxis.VisibleLinesCollection visibleLines) [0x00238] in <750c8951b0c04cf28c87bd3cd2791c19>:0 
[MonoDroid]   at Syncfusion.Android.TreeView.TreeNodesContainerBase.EnsureItems () [0x0001b] in <750c8951b0c04cf28c87bd3cd2791c19>:0 
[MonoDroid]   at Syncfusion.Android.TreeView.TreeNodeContainer.OnMeasureTreeNodeContainer (System.Double width, System.Double height) [0x000a0] in <750c8951b0c04cf28c87bd3cd2791c19>:0 
[MonoDroid]   at Syncfusion.Android.TreeView.TreeNodeContainer.OnMeasure (System.Int32 width, System.Int32 height) [0x00000] in <750c8951b0c04cf28c87bd3cd2791c19>:0 
[MonoDroid]   at Android.Views.View.n_OnMeasure_II (System.IntPtr jnienv, System.IntPtr native__this, System.Int32 widthMeasureSpec, System.Int32 heightMeasureSpec) [0x00009] in <c7e98e7ffdc14e358cd8f1a94c33b7db>:0 
[MonoDroid]   at (wrapper dynamic-method) System.Object.26(intptr,intptr,int,int)


RS Rawoof Sharief Muthuja Sherif Syncfusion Team October 17, 2018 12:37 PM UTC

 
We have prepared the sample based on the code snippet you have shared. We have already fixed an issue while loading treeview inside the master detail page. We have checked the stack trace that you have given in the last update which is different from the issue we have fixed. Unfortunately, the reported issue does not replicate at our end. Treeview is loaded in the view as expected. 
 
For your reference we have attached the sample and you can download it from the below link. 
 
 
Can you please check with the above sample? whether you are facing similar issue in our sample. If no, we would request you to modify the sample or share the sample which reproduce the issue which would highly helpful to us to analyze the issue better and update you an appropriate solution.   
 
Regards, 
Rawoof M. 


Loader.
Up arrow icon