roubachof / Sharpnado.Presentation.Forms

Presentation layer: Xamarin Forms custom components and renderers
593 stars 74 forks source link

horizontal list view never renders cause of null #106

Closed champcbg closed 4 years ago

champcbg commented 4 years ago

Platform (please complete the following information):

Describe the bug A clear and concise description of what the bug is. when i navigate to the page in the app that the has the horizontalListView, the Null Exception (pasted Below) is thrown. the page never renders and app crashes.

Below Xaml of my page layout.

<StackLayout  Grid.Row="1">
                <!--Margin="{core:OnPlatformOrientationThickness PhonePortrait='20,32',
                PhoneLandscape='150,32',
                TabletPortrait='200,50',
                TabletLandscape='300,50',
                Desktop='30'}"-->
                <renderedViews:HorizontalListView CollectionPadding="16"
                                  ItemSpacing="8"
                                  EnableDragAndDrop="True"
                                  ItemWidth="110"
                                  ItemHeight="120"
                                  ItemsSource="{Binding Images}"
                                  ListLayout="Grid">
                    <renderedViews:HorizontalListView.ItemTemplate>
                        <DataTemplate>
                            <renderedViews:DraggableViewCell x:Name="DraggableViewCell">
                                <ContentView>
                                    <renderedViews:MaterialFrame Margin="4"
                                                 Padding="{StaticResource StandardThickness}"
                                                 Elevation="4">

                                        <Frame.Triggers>
                                            <DataTrigger Binding="{Binding Source={x:Reference DraggableViewCell}, Path=IsDragAndDropping}"
                                         TargetType="renderedViews:MaterialFrame"
                                         Value="True">
                                                <Setter Property="Elevation" Value="8" />
                                            </DataTrigger>
                                        </Frame.Triggers>

                                        <Image Source="{Binding PrimaryImage.AppPrivatePath}"
                                               Aspect="AspectFill"
                                               HeightRequest="60"
                                               WidthRequest="60" />

                                        <!--<Grid ColumnSpacing="0" RowSpacing="0">
                                            <Grid.RowDefinitions>
                                                <RowDefinition Height="2*" />
                                                <RowDefinition Height="*" />
                                            </Grid.RowDefinitions>
                                            <abstractions:CircleImage Grid.Row="0"
                                                      Style="{StaticResource SmallAvatar}"
                                                      Aspect="AspectFill"
                                                      Source="{Binding ImageUrl}" />
                                            <Label Grid.Row="1"
                                   Margin="{StaticResource MediumTopThickness}"
                                   Style="{StaticResource TextSmallCaption}"
                                   HorizontalTextAlignment="Center"
                                   Text="{Binding Name}" />
                                        </Grid>-->
                                    </renderedViews:MaterialFrame>
                                </ContentView>
                            </renderedViews:DraggableViewCell>
                        </DataTemplate>
                    </renderedViews:HorizontalListView.ItemTemplate>
                </renderedViews:HorizontalListView>

            </StackLayout>

To Reproduce Steps to reproduce the behavior:

  1. Navigate to page with Horizontal ListView
  2. See error

Exceptions (if applicable) Copy paste the exception and the stack trace

04-22 18:30:37.582 I/MonoDroid(19892): UNHANDLED EXCEPTION:
04-22 18:30:37.584 I/MonoDroid(19892): System.NullReferenceException: Object reference not set to an instance of an object.
04-22 18:30:37.584 I/MonoDroid(19892):   at Sharpnado.Presentation.Forms.Droid.Renderers.HorizontalList.SpaceItemDecoration..ctor (System.Int32 spaceDp) [0x00006] in D:\Dev\Sharpnado\src\Xamarin-Forms-Practices\Sharpnado.Presentation.Forms\Sharpnado.Presentation.Forms.Droid\Renderers\HorizontalList\ResponsiveGridLayoutManager.cs:32 
04-22 18:30:37.584 I/MonoDroid(19892):   at Sharpnado.Presentation.Forms.Droid.Renderers.HorizontalList.AndroidHorizontalListViewRenderer.SetListLayout (Android.Support.V7.Widget.RecyclerView recyclerView) [0x0008b] in D:\Dev\Sharpnado\src\Xamarin-Forms-Practices\Sharpnado.Presentation.Forms\Sharpnado.Presentation.Forms.Droid\Renderers\HorizontalList\AndroidHorizontalListViewRenderer.cs:244 
04-22 18:30:37.584 I/MonoDroid(19892):   at Sharpnado.Presentation.Forms.Droid.Renderers.HorizontalList.AndroidHorizontalListViewRenderer.CreateView (Sharpnado.Presentation.Forms.RenderedViews.HorizontalListView horizontalList) [0x00038] in D:\Dev\Sharpnado\src\Xamarin-Forms-Practices\Sharpnado.Presentation.Forms\Sharpnado.Presentation.Forms.Droid\Renderers\HorizontalList\AndroidHorizontalListViewRenderer.cs:191 
04-22 18:30:37.584 I/MonoDroid(19892):   at Sharpnado.Presentation.Forms.Droid.Renderers.HorizontalList.AndroidHorizontalListViewRenderer.OnElementChanged (Xamarin.Forms.Platform.Android.ElementChangedEventArgs`1[TElement] e) [0x000bb] in D:\Dev\Sharpnado\src\Xamarin-Forms-Practices\Sharpnado.Presentation.Forms\Sharpnado.Presentation.Forms.Droid\Renderers\HorizontalList\AndroidHorizontalListViewRenderer.cs:91 
04-22 18:30:37.584 I/MonoDroid(19892):   at Xamarin.Forms.Platform.Android.VisualElementRenderer`1[TElement].SetElement (TElement element) [0x000b8] in D:\a\1\s\Xamarin.Forms.Platform.Android\VisualElementRenderer.cs:240 
04-22 18:30:37.584 I/MonoDroid(19892):   at Xamarin.Forms.Platform.Android.VisualElementRenderer`1[TElement].Xamarin.Forms.Platform.Android.IVisualElementRenderer.SetElement (Xamarin.Forms.VisualElement element) [0x00033] in D:\a\1\s\Xamarin.Forms.Platform.Android\VisualElementRenderer.cs:133 
04-22 18:30:37.584 I/MonoDroid(19892):   at Xamarin.Forms.Platform.Android.Platform.CreateRenderer (Xamarin.Forms.VisualElement element, Android.Content.Context context) [0x0001f] in D:\a\1\s\Xamarin.Forms.Platform.Android\Platform.cs:350 
04-22 18:30:37.584 I/MonoDroid(19892):   at Xamarin.Forms.Platform.Android.VisualElementPackager.AddChild (Xamarin.Forms.VisualElement view, Xamarin.Forms.Platform.Android.IVisualElementRenderer oldRenderer, Xamarin.Forms.Platform.Android.RendererPool pool, System.Boolean sameChildren) [0x000af] in D:\a\1\s\Xamarin.Forms.Platform.Android\VisualElementPackager.cs:137 
04-22 18:30:37.584 I/MonoDroid(19892):   at Xamarin.Forms.Platform.Android.VisualElementPackager.SetElement (Xamarin.Forms.VisualElement oldElement, Xamarin.Forms.VisualElement newElement) [0x00163] in D:\a\1\s\Xamarin.Forms.Platform.Android\VisualElementPackager.cs:347 
04-22 18:30:37.585 I/MonoDroid(19892):   at Xamarin.Forms.Platform.Android.VisualElementPackager.Load () [0x00000] in D:\a\1\s\Xamarin.Forms.Platform.Android\VisualElementPackager.cs:109 
04-22 18:30:37.585 I/MonoDroid(19892):   at Xamarin.Forms.Platform.Android.VisualElementRenderer`1[TElement].SetPackager (Xamarin.Forms.Platform.Android.VisualElementPackager packager) [0x00007] in D:\a\1\s\Xamarin.Forms.Platform.Android\VisualElementRenderer.cs:449 
04-22 18:30:37.585 I/MonoDroid(19892):   at Xamarin.Forms.Platform.Android.VisualElementRenderer`1[TElement].SetElement (TElement element) [0x000d5] in D:\a\1\s\Xamarin.Forms.Platform.Android\VisualElementRenderer.cs:243 
04-22 18:30:37.585 I/MonoDroid(19892):   at Xamarin.Forms.Platform.Android.VisualElementRenderer`1[TElement].Xamarin.Forms.Platform.Android.IVisualElementRenderer.SetElement (Xamarin.Forms.VisualElement element) [0x00033] in D:\a\1\s\Xamarin.Forms.Platform.Android\VisualElementRenderer.cs:133 
04-22 18:30:37.585 I/MonoDroid(19892):   at Xamarin.Forms.Platform.Android.Platform.CreateRenderer (Xamarin.Forms.VisualElement element, Android.Content.Context context) [0x0001f] in D:\a\1\s\Xamarin.Forms.Platform.Android\Platform.cs:350 
04-22 18:30:37.585 I/MonoDroid(19892):   at Xamarin.Forms.Platform.Android.VisualElementPackager.AddChild (Xamarin.Forms.VisualElement view, Xamarin.Forms.Platform.Android.IVisualElementRenderer oldRenderer, Xamarin.Forms.Platform.Android.RendererPool pool, System.Boolean sameChildren) [0x000af] in D:\a\1\s\Xamarin.Forms.Platform.Android\VisualElementPackager.cs:137 
04-22 18:30:37.585 I/MonoDroid(19892):   at Xamarin.Forms.Platform.Android.VisualElementPackager.SetElement (Xamarin.Forms.VisualElement oldElement, Xamarin.Forms.VisualElement newElement) [0x00163] in D:\a\1\s\Xamarin.Forms.Platform.Android\VisualElementPackager.cs:347 
04-22 18:30:37.585 I/MonoDroid(19892):   at Xamarin.Forms.Platform.Android.VisualElementPackager.Load () [0x00000] in D:\a\1\s\Xamarin.Forms.Platform.Android\VisualElementPackager.cs:109 
04-22 18:30:37.588 I/MonoDroid(19892):   at Xamarin.Forms.Platform.Android.VisualElementRenderer`1[TElement].SetPackager (Xamarin.Forms.Platform.Android.VisualElementPackager packager) [0x00007] in D:\a\1\s\Xamarin.Forms.Platform.Android\VisualElementRenderer.cs:449 
04-22 18:30:37.588 I/MonoDroid(19892):   at Xamarin.Forms.Platform.Android.VisualElementRenderer`1[TElement].SetElement (TElement element) [0x000d5] in D:\a\1\s\Xamarin.Forms.Platform.Android\VisualElementRenderer.cs:243 
04-22 18:30:37.588 I/MonoDroid(19892):   at Xamarin.Forms.Platform.Android.VisualElementRenderer`1[TElement].Xamarin.Forms.Platform.Android.IVisualElementRenderer.SetElement (Xamarin.Forms.VisualElement element) [0x00033] in D:\a\1\s\Xamarin.Forms.Platform.Android\VisualElementRenderer.cs:133 
04-22 18:30:37.588 I/MonoDroid(19892):   at Xamarin.Forms.Platform.Android.Platform.CreateRenderer (Xamarin.Forms.VisualElement element, Android.Content.Context context) [0x0001f] in D:\a\1\s\Xamarin.Forms.Platform.Android\Platform.cs:350 
04-22 18:30:37.588 I/MonoDroid(19892):   at Xamarin.Forms.Platform.Android.VisualElementPackager.AddChild (Xamarin.Forms.VisualElement view, Xamarin.Forms.Platform.Android.IVisualElementRenderer oldRenderer, Xamarin.Forms.Platform.Android.RendererPool pool, System.Boolean sameChildren) [0x000af] in D:\a\1\s\Xamarin.Forms.Platform.Android\VisualElementPackager.cs:137 
04-22 18:30:37.589 I/MonoDroid(19892):   at Xamarin.Forms.Platform.Android.VisualElementPackager.SetElement (Xamarin.Forms.VisualElement oldElement, Xamarin.Forms.VisualElement newElement) [0x00163] in D:\a\1\s\Xamarin.Forms.Platform.Android\VisualElementPackager.cs:347 
04-22 18:30:37.589 I/MonoDroid(19892):   at Xamarin.Forms.Platform.Android.VisualElementPackager.Load () [0x00000] in D:\a\1\s\Xamarin.Forms.Platform.Android\VisualElementPackager.cs:109 
04-22 18:30:37.589 I/MonoDroid(19892):   at Xamarin.Forms.Platform.Android.VisualElementRenderer`1[TElement].SetPackager (Xamarin.Forms.Platform.Android.VisualElementPackager packager) [0x00007] in D:\a\1\s\Xamarin.Forms.Platform.Android\VisualElementRenderer.cs:449 
04-22 18:30:37.589 I/MonoDroid(19892):   at Xamarin.Forms.Platform.Android.VisualElementRenderer`1[TElement].SetElement (TElement element) [0x000d5] in D:\a\1\s\Xamarin.Forms.Platform.Android\VisualElementRenderer.cs:243 
04-22 18:30:37.589 I/MonoDroid(19892):   at Xamarin.Forms.Platform.Android.VisualElementRenderer`1[TElement].Xamarin.Forms.Platform.Android.IVisualElementRenderer.SetElement (Xamarin.Forms.VisualElement element) [0x00033] in D:\a\1\s\Xamarin.Forms.Platform.Android\VisualElementRenderer.cs:133 
04-22 18:30:37.589 I/MonoDroid(19892):   at Xamarin.Forms.Platform.Android.Platform.CreateRenderer (Xamarin.Forms.VisualElement element, Android.Support.V4.App.FragmentManager fragmentManager, Android.Content.Context context) [0x00031] in D:\a\1\s\Xamarin.Forms.Platform.Android\Platform.cs:397 
04-22 18:30:37.589 I/MonoDroid(19892):   at Xamarin.Forms.Platform.Android.AppCompat.FragmentContainer.OnCreateView (Android.Views.LayoutInflater inflater, Android.Views.ViewGroup container, Android.OS.Bundle savedInstanceState) [0x00008] in D:\a\1\s\Xamarin.Forms.Platform.Android\AppCompat\FragmentContainer.cs:64 
04-22 18:30:37.589 I/MonoDroid(19892):   at Android.Support.V4.App.Fragment.n_OnCreateView_Landroid_view_LayoutInflater_Landroid_view_ViewGroup_Landroid_os_Bundle_ (System.IntPtr jnienv, System.IntPtr native__this, System.IntPtr native_inflater, System.IntPtr native_container, System.IntPtr native_savedInstanceState) [0x00020] in <fefee6c2c695459088a9df092723e052>:0 
04-22 18:30:37.589 I/MonoDroid(19892):   at (wrapper dynamic-method) Android.Runtime.DynamicMethodNameCounter.84(intptr,intptr,intptr,intptr,intptr)

Screenshots (if applicable) If applicable, add screenshots to help explain your problem.

roubachof commented 4 years ago

You said that null reference exception happens on both platform, but you only copied the Android exception. Please add as well the iOS exception.

champcbg commented 4 years ago

Sorry I changed it just to android as that is have spent my primary time testing

roubachof commented 4 years ago

mmmh that's weird... where are you calling this:

SharpnadoInitializer.Initialize()

in your android code?

champcbg commented 4 years ago

Im not calling it anywhere, I must of missed that in the documentation, i dont recalling seeing anywhere.

Where should SharpnadoInitializer.Initialize() be called?

roubachof commented 4 years ago

IMPORTANT: On platform projects, call SharpnadoInitializer.Initialize() after Xamarin.Forms.Forms.Init() and before LoadApplication(new App()).

champcbg commented 4 years ago

ok thanks going to try that now, i also just saw that initialize in the iOS SillyCompany Example. But its not in the Android example.

image

Thanks, for the help.

champcbg commented 4 years ago

the grid shows up thank you