System.NullReferenceException on LoadApplication(new App());

NicoEngler.6615NicoEngler.6615 USMember
edited February 2016 in Xamarin.Forms

Hello, I am just starting to develop apps with Xamarin.Forms and I ran into an error while trying to create a GridView example. I'm getting a System.NullReferenceException Exception after LoadApplication(new App());.

App.cs

(Sorry but I could not make the following code appear formatted)

` public App()
{
RegisterViews();
MainPage = new NavigationPage((Page)ViewFactory.CreatePage<MainViewModel, MainView>());
}

    private void RegisterViews()
    {
        ViewFactory.Register<MainView, MainViewModel>();
    }`

MainView.xaml

<?xml version="1.0" encoding="utf-8" ?> <ContentPage xmlns="http://xamarin.com/schemas/2014/forms" xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" xmlns:controls="clr-namespace:XLabs.Forms.Controls;assembly=XLabs.Forms" x:Class="XLabsGridViewExample.View.MainView"> <Label Text="{Binding Message}" VerticalOptions="Center" HorizontalOptions="Center" /> <Grid> <Grid.RowDefinitions> <RowDefinition Height="60" /> <RowDefinition Height="*" /> </Grid.RowDefinitions> <Grid.ColumnDefinitions> <ColumnDefinition Width="33*" /> <ColumnDefinition Width="33*" /> <ColumnDefinition Width="33*" /> </Grid.ColumnDefinitions> <controls:GridView x:Name="GrdView" ItemWidth ="152" ItemHeight = "200" ItemsSource="{Binding Images}" Grid.Row="1" Grid.ColumnSpan="3"> <controls:GridView.ItemTemplate> <DataTemplate > <ViewCell> <ViewCell.View> <Image Source="{Binding}" /> </ViewCell.View> </ViewCell> </DataTemplate> </controls:GridView.ItemTemplate> </controls:GridView> </Grid> </ContentPage>

MainViewModel.cs

public class MainViewModel : XLabs.Forms.Mvvm.ViewModel { public MainViewModel() { // not even filled yet } }

I have attachend an excerpt of my log. Any ideas on what is going on here?

Answers

  • NicoEngler.6615NicoEngler.6615 USMember
    edited February 2016

    So today I managed to get a more detailed exception. After googling for a while it seems like some others are experiencing the same problem. (I switched from GridView to ImageGallery to check if the problem occurs on other controls as well)

    02-28 11:19:46.180 I/MonoDroid( 5872): UNHANDLED EXCEPTION:
    02-28 11:19:46.181 I/MonoDroid( 5872): System.NullReferenceException: Object reference not set to an instance of an object
    02-28 11:19:46.181 I/MonoDroid( 5872): at XLabs.Forms.Controls.ImageGalleryRenderer.Bind (XLabs.Forms.Controls.ImageGallery newElement) [0x0002d] in :0
    02-28 11:19:46.181 I/MonoDroid( 5872): at XLabs.Forms.Controls.ImageGalleryRenderer.OnElementChanged (Xamarin.Forms.Platform.Android.ElementChangedEventArgs1 e) [0x00033] in <filename unknown>:0 02-28 11:19:46.181 I/MonoDroid( 5872): at Xamarin.Forms.Platform.Android.VisualElementRenderer1[TElement].SetElement (Xamarin.Forms.Platform.Android.TElement element) [0x000fc] in :0
    02-28 11:19:46.181 I/MonoDroid( 5872): at Xamarin.Forms.Platform.Android.VisualElementRenderer1[TElement].Xamarin.Forms.Platform.Android.IVisualElementRenderer.SetElement (Xamarin.Forms.VisualElement element) [0x00027] in <filename unknown>:0 02-28 11:19:46.181 I/MonoDroid( 5872): at Xamarin.Forms.Platform.Android.Platform.CreateRenderer (Xamarin.Forms.VisualElement element) [0x0001f] in <filename unknown>:0 02-28 11:19:46.181 I/MonoDroid( 5872): at Xamarin.Forms.Platform.Android.VisualElementPackager.AddChild (Xamarin.Forms.VisualElement view, IVisualElementRenderer oldRenderer, Xamarin.Forms.Platform.Android.RendererPool pool, Boolean sameChildren) [0x00023] in <filename unknown>:0 02-28 11:19:46.181 I/MonoDroid( 5872): at Xamarin.Forms.Platform.Android.VisualElementPackager.SetElement (Xamarin.Forms.VisualElement oldElement, Xamarin.Forms.VisualElement newElement) [0x0010d] in <filename unknown>:0 02-28 11:19:46.181 I/MonoDroid( 5872): at Xamarin.Forms.Platform.Android.VisualElementPackager.Load () [0x0000d] in <filename unknown>:0 02-28 11:19:46.181 I/MonoDroid( 5872): at Xamarin.Forms.Platform.Android.VisualElementRenderer1[TElement].SetPackager (Xamarin.Forms.Platform.Android.VisualElementPackager packager) [0x00007] in :0
    02-28 11:19:46.181 I/MonoDroid( 5872): at Xamarin.Forms.Platform.Android.VisualElementRenderer1[TElement].SetElement (Xamarin.Forms.Platform.Android.TElement element) [0x00118] in <filename unknown>:0 02-28 11:19:46.181 I/MonoDroid( 5872): at Xamarin.Forms.Platform.Android.VisualElementRenderer1[TElement].Xamarin.Forms.Platform.Android.IVisualElementRenderer.SetElement (Xamarin.Forms.VisualElement element) [0x00027] in :0
    02-28 11:19:46.181 I/MonoDroid( 5872): at Xamarin.Forms.Platform.Android.Platform.CreateRenderer (Xamarin.Forms.VisualElement element) [0x0001f] in :0
    02-28 11:19:46.181 I/MonoDroid( 5872): at Xamarin.Forms.Platform.Android.VisualElementPackager.AddChild (Xamarin.Forms.VisualElement view, IVisualElementRenderer oldRenderer, Xamarin.Forms.Platform.Android.RendererPool pool, Boolean sameChildren) [0x00023] in :0
    02-28 11:19:46.181 I/MonoDroid( 5872): at Xamarin.Forms.Platform.Android.VisualElementPackager.SetElement (Xamarin.Forms.VisualElement oldElement, Xamarin.Forms.VisualElement newElement) [0x0010d] in :0
    02-28 11:19:46.181 I/MonoDroid( 5872): at Xamarin.Forms.Platform.Android.VisualElementPackager.Load () [0x0000d] in :0
    02-28 11:19:46.181 I/MonoDroid( 5872): at Xamarin.Forms.Platform.Android.VisualElementRenderer1[TElement].SetPackager (Xamarin.Forms.Platform.Android.VisualElementPackager packager) [0x00007] in <filename unknown>:0 02-28 11:19:46.181 I/MonoDroid( 5872): at Xamarin.Forms.Platform.Android.VisualElementRenderer1[TElement].SetElement (Xamarin.Forms.Platform.Android.TElement element) [0x00118] in :0
    02-28 11:19:46.181 I/MonoDroid( 5872): at Xamarin.Forms.Platform.Android.VisualElementRenderer1[TElement].Xamarin.Forms.Platform.Android.IVisualElementRenderer.SetElement (Xamarin.Forms.VisualElement element) [0x00027] in <filename unknown>:0 02-28 11:19:46.182 I/MonoDroid( 5872): at Xamarin.Forms.Platform.Android.Platform.CreateRenderer (Xamarin.Forms.VisualElement element) [0x0001f] in <filename unknown>:0 02-28 11:19:46.182 I/MonoDroid( 5872): at Xamarin.Forms.Platform.Android.VisualElementPackager.AddChild (Xamarin.Forms.VisualElement view, IVisualElementRenderer oldRenderer, Xamarin.Forms.Platform.Android.RendererPool pool, Boolean sameChildren) [0x00023] in <filename unknown>:0 02-28 11:19:46.182 I/MonoDroid( 5872): at Xamarin.Forms.Platform.Android.VisualElementPackager.SetElement (Xamarin.Forms.VisualElement oldElement, Xamarin.Forms.VisualElement newElement) [0x0010d] in <filename unknown>:0 02-28 11:19:46.182 I/MonoDroid( 5872): at Xamarin.Forms.Platform.Android.VisualElementPackager.Load () [0x0000d] in <filename unknown>:0 02-28 11:19:46.182 I/MonoDroid( 5872): at Xamarin.Forms.Platform.Android.VisualElementRenderer1[TElement].SetPackager (Xamarin.Forms.Platform.Android.VisualElementPackager packager) [0x00007] in :0
    02-28 11:19:46.182 I/MonoDroid( 5872): at Xamarin.Forms.Platform.Android.VisualElementRenderer1[TElement].SetElement (Xamarin.Forms.Platform.Android.TElement element) [0x00118] in <filename unknown>:0 02-28 11:19:46.182 I/MonoDroid( 5872): at Xamarin.Forms.Platform.Android.VisualElementRenderer1[TElement].Xamarin.Forms.Platform.Android.IVisualElementRenderer.SetElement (Xamarin.Forms.VisualElement element) [0x00027] in :0
    02-28 11:19:46.182 I/MonoDroid( 5872): at Xamarin.Forms.Platform.Android.Platform.CreateRenderer (Xamarin.Forms.VisualElement element) [0x0001f] in :0
    02-28 11:19:46.182 I/MonoDroid( 5872): at Xamarin.Forms.Platform.Android.NavigationRenderer.SwitchContentAsync (Xamarin.Forms.Page view, Boolean animated, Boolean removed) [0x00028] in :0
    02-28 11:19:46.182 I/MonoDroid( 5872): at Xamarin.Forms.Platform.Android.NavigationRenderer.OnPushAsync (Xamarin.Forms.Page view, Boolean animated) [0x00000] in :0
    02-28 11:19:46.182 I/MonoDroid( 5872): at Xamarin.Forms.Platform.Android.NavigationRenderer.PushViewAsync (Xamarin.Forms.Page page, Boolean animated) [0x00000] in :0
    02-28 11:19:46.182 I/MonoDroid( 5872): at Xamarin.Forms.Platform.Android.NavigationRenderer.b__4_0 (Xamarin.Forms.Page p) [0x00000] in :0
    02-28 11:19:46.182 I/MonoDroid( 5872): at Xamarin.Forms.EnumerableExtensions.ForEach[T] (IEnumerable1 enumeration, System.Action1 action) [0x00010] in :0
    02-28 11:19:46.182 I/MonoDroid( 5872): at Xamarin.Forms.Platform.Android.NavigationRenderer.OnElementChanged (Xamarin.Forms.Platform.Android.ElementChangedEventArgs1 e) [0x000de] in <filename unknown>:0 02-28 11:19:46.182 I/MonoDroid( 5872): at Xamarin.Forms.Platform.Android.VisualElementRenderer1[TElement].SetElement (Xamarin.Forms.Platform.Android.TElement element) [0x000fc] in :0
    02-28 11:19:46.182 I/MonoDroid( 5872): at Xamarin.Forms.Platform.Android.VisualElementRenderer`1[TElement].Xamarin.Forms.Platform.Android.IVisualElementRenderer.SetElement (Xamarin.Forms.VisualElement element) [0x00027] in :0
    02-28 11:19:46.182 I/MonoDroid( 5872): at Xamarin.Forms.Platform.Android.Platform.CreateRenderer (Xamarin.Forms.VisualElement element) [0x0001f] in :0
    02-28 11:19:46.182 I/MonoDroid( 5872): at Xamarin.Forms.Platform.Android.Platform.AddChild (Xamarin.Forms.VisualElement view, Boolean layout) [0x00015] in :0
    02-28 11:19:46.182 I/MonoDroid( 5872): at Xamarin.Forms.Platform.Android.Platform.SetPage (Xamarin.Forms.Page newRoot) [0x00090] in :0
    02-28 11:19:46.182 I/MonoDroid( 5872): at Xamarin.Forms.Platform.Android.FormsApplicationActivity.InternalSetPage (Xamarin.Forms.Page page) [0x000b7] in :0
    02-28 11:19:46.182 I/MonoDroid( 5872): at Xamarin.Forms.Platform.Android.FormsApplicationActivity.SetMainPage () [0x0000c] in :0
    02-28 11:19:46.182 I/MonoDroid( 5872): at Xamarin.Forms.Platform.Android.FormsApplicationActivity.LoadApplication (Xamarin.Forms.Application application) [0x0002d] in :0

Sign In or Register to comment.