System.NullReferenceException: Object reference not set to an instance of an object
at Syncfusion.ListView.XForms.LayoutBase.GetAutoFitItemSize (Syncfusion.ListView.XForms.ListViewItemInfoBase itemInfo, System.Double& itemSize, System.Double itemSpacing, System.Int32 spanCount) [0x000cb] in <9dbe1f5143c64addbe242929584a687b>:0
at Syncfusion.ListView.XForms.LinearLayout.GetAutoFitItemSize (Syncfusion.ListView.XForms.ListViewItemInfoBase itemInfo, System.Double& itemSize, System.Double itemSpacing) [0x00000] in <9dbe1f5143c64addbe242929584a687b>:0
at Syncfusion.ListView.XForms.LinearLayout.SetRowHeight (Syncfusion.ListView.XForms.ListViewItemInfo itemInfo, System.Int32 index, System.Double& size, System.Double itemSpacing) [0x00011] in <9dbe1f5143c64addbe242929584a687b>:0
at Syncfusion.ListView.XForms.LinearLayout.SetRowHeight (Syncfusion.ListView.XForms.ListViewItemInfo itemInfo, System.Double itemSpacing) [0x000b0] in <9dbe1f5143c64addbe242929584a687b>:0
at Syncfusion.ListView.XForms.LinearLayout.EnsureItems (Syncfusion.GridCommon.ScrollAxis.VisibleLinesCollection visibleLines) [0x00303] in <9dbe1f5143c64addbe242929584a687b>:0
at Syncfusion.ListView.XForms.VisualContainer.EnsureItems () [0x0002c] in <9dbe1f5143c64addbe242929584a687b>:0
at Syncfusion.ListView.XForms.VisualContainer.OnSizeAllocated (System.Double width, System.Double height) [0x00040] in <9dbe1f5143c64addbe242929584a687b>:0
at Xamarin.Forms.VisualElement.SizeAllocated (System.Double width, System.Double height) [0x00000] in D:\a\1\s\Xamarin.Forms.Core\VisualElement.cs:798
at Xamarin.Forms.VisualElement.SetSize (System.Double width, System.Double height) [0x00021] in D:\a\1\s\Xamarin.Forms.Core\VisualElement.cs:1027
at Xamarin.Forms.VisualElement.set_Bounds (Xamarin.Forms.Rectangle value) [0x0005d] in D:\a\1\s\Xamarin.Forms.Core\VisualElement.cs:277
at Xamarin.Forms.VisualElement.Layout (Xamarin.Forms.Rectangle bounds) [0x00000] in D:\a\1\s\Xamarin.Forms.Core\VisualElement.cs:684
at Xamarin.Forms.Layout.LayoutChildIntoBoundingRegion (Xamarin.Forms.VisualElement child, Xamarin.Forms.Rectangle region) [0x001da] in D:\a\1\s\Xamarin.Forms.Core\Layout.cs:177
at Syncfusion.ListView.XForms.ExtendedScrollView.LayoutChildren (System.Double x, System.Double y, System.Double width, System.Double height) [0x00058] in <9dbe1f5143c64addbe242929584a687b>:0
at Xamarin.Forms.Layout.UpdateChildrenLayout () [0x0014b] in D:\a\1\s\Xamarin.Forms.Core\Layout.cs:263
at Xamarin.Forms.Layout.OnSizeAllocated (System.Double width, System.Double height) [0x0000f] in D:\a\1\s\Xamarin.Forms.Core\Layout.cs:223
at Xamarin.Forms.VisualElement.SizeAllocated (System.Double width, System.Double height) [0x00000] in D:\a\1\s\Xamarin.Forms.Core\VisualElement.cs:798
at Xamarin.Forms.VisualElement.SetSize (System.Double width, System.Double height) [0x00021] in D:\a\1\s\Xamarin.Forms.Core\VisualElement.cs:1027
at Xamarin.Forms.VisualElement.set_Bounds (Xamarin.Forms.Rectangle value) [0x0005d] in D:\a\1\s\Xamarin.Forms.Core\VisualElement.cs:277
at Xamarin.Forms.VisualElement.Layout (Xamarin.Forms.Rectangle bounds) [0x00000] in D:\a\1\s\Xamarin.Forms.Core\VisualElement.cs:684
at Syncfusion.ListView.XForms.SfListView.LayoutChildren (System.Double x, System.Double y, System.Double width, System.Double height) [0x0036f] in <9dbe1f5143c64addbe242929584a687b>:0
Hey SyncFusion Team,
I need to bring this topic up because I am facing the exact same problem but on android platform. As soon as I use AutoFitMode with either DynamicHeight or Height, my android app crashes with
java.lang.NullPointerException: Attempt to invoke interface method 'int java.lang.CharSequence.length()' on a null object reference
when my underlaying observable collection is changing. This does not happen on UWP.
Are there still any known issues with that functionality?
Xamarin.Forms 5.0.0.2478
Synfusion.Xamarin.SfListView 20.2.0.38
Microsoft Visual Studio Community 2022 17.2.6
Hi Manuel,
We have checked the reported query "Null Reference Exception when autosizing ListView" from our end. We would like to inform you that changing observable collection at runtime with AutoFitMode as height or Dynamic height works fine without any crash. We have attached a workable sample for your reference.
Also, please modify the sample to the reported scenario and share the below details, which would be helpful for us to check on it and provide you with the solution as soon as possible.
Regards,
Suthi Yuvaraj
Here is a screencast where hte problem is dispalyed, with fixed height at beginning everything works as expected. When switching to AutoFitMode the app starts crashing randomly when the pages are changed with the flyoutmenu. Debugging shows this occuring when manipulating the ItemSources content.
Xamarin.Forms 5.0.0.2478
Synfusion.Xamarin.SfListView 20.2.0.38
I would upload the whole project but it is way to big for it and needs expertise to get everything set up - sry.
Here is the code snippet.
<sf:SfListView x:Name="RepeaterItems"
ItemsSource="{x:Binding BuildingPartItems}"
ItemTemplate="{x:StaticResource ActionableItemTemplateSelector}"
AutoFitMode="DynamicHeight"
AllowSwiping="{x:Binding EditModeEnabled}"
SelectionMode="None"
DragStartMode="OnDragIndicator">
<sf:SfListView.DragDropController>
<sf:DragDropController UpdateSource="True" />
</sf:SfListView.DragDropController>
<sf:SfListView.RightSwipeTemplate>
<DataTemplate >
<Grid>
<Grid BackgroundColor="{StaticResource KNXBlue}" HorizontalOptions="Fill" VerticalOptions="Fill" Grid.Column="0">
<Grid VerticalOptions="Center" HorizontalOptions="Center">
<Grid.GestureRecognizers>
<TapGestureRecognizer Command="{x:Binding BindingContext.DisplayEditPopupCommand, Source={x:Reference RepeaterItems}}" CommandParameter="{x:Binding .}"/>
<TapGestureRecognizer Command="{x:Binding BindingContext.ResetSwipeCommand, Source={x:Reference RepeaterItems}}" CommandParameter="{x:Reference RepeaterItems}"/>
</Grid.GestureRecognizers>
<Image Grid.Column="0"
Grid.Row="0"
BackgroundColor="Transparent"
HeightRequest="20"
WidthRequest="20">
<Image.Source>
<FontImageSource FontFamily="MaterialDesignIcons"
Glyph="{x:Static fonts:MaterialDesignIcons.Pencil}"
Color="{AppThemeBinding Dark={StaticResource DarkFontColor}, Light={StaticResource LightFontColor}}" />
</Image.Source>
</Image>
</Grid>
</Grid>
</Grid>
</DataTemplate>
</sf:SfListView.RightSwipeTemplate>
<sf:SfListView.LeftSwipeTemplate>
<DataTemplate >
<Grid>
<Grid BackgroundColor="#DC595F" HorizontalOptions="Fill" VerticalOptions="Fill" Grid.Column="0">
<Grid VerticalOptions="Center" HorizontalOptions="Center">
<Grid.GestureRecognizers>
<TapGestureRecognizer Command="{x:Binding BindingContext.DeleteItemCommand, Source={x:Reference RepeaterItems}}" CommandParameter="{x:Binding .}"/>
<TapGestureRecognizer Command="{x:Binding BindingContext.ResetSwipeCommand, Source={x:Reference RepeaterItems}}" CommandParameter="{x:Reference RepeaterItems}"/>
</Grid.GestureRecognizers>
<Image Grid.Column="0"
Grid.Row="0"
BackgroundColor="Transparent"
HeightRequest="20"
WidthRequest="20">
<Image.Source>
<FontImageSource FontFamily="MaterialDesignIcons"
Glyph="{x:Static fonts:MaterialDesignIcons.Delete}"
Color="{AppThemeBinding Dark={StaticResource DarkFontColor}, Light={StaticResource LightFontColor}}" />
</Image.Source>
</Image>
</Grid>
</Grid>
</Grid>
</DataTemplate>
</sf:SfListView.LeftSwipeTemplate>
</sf:SfListView>
Hi Manuel,
We have checked the reported query from our end. Flyout Page with SfListView , AutoFitMode as height or Dynamic height works fine without any crash. We have attached a workable sample for your reference.
Also, please modify the sample to the reported scenario and share the below details, which would be helpful for us to check on it and provide you with the solution as soon as possible.
Regards,
Suthi Yuvaraj