Hello! When clicking an text-entry-box i get null reference exception object reference not set to an

Jane_NatalieJane_Natalie Member ✭✭✭

"Unhandled Exception:
System.NullReferenceException: Object reference not set to an instance of an object."

This is my xaml code from the page in which the text-entry-box is in. The exception is thrown when I click on the entry box, before I am able to type anything in it.
----xaml, the page with the entry box--------

<ContentPage.BindingContext>

</ContentPage.BindingContext>

<ContentPage.Content>
    <StackLayout HorizontalOptions="Center" VerticalOptions="Center" Spacing="10">

        <Entry Text="{Binding Keyword}"  MaxLength="15"/>

        <Button Text="Send" BorderColor="Black" TextColor="White"   FontAttributes="Bold" FontSize="20" BackgroundColor="#f49131" 
    Command="{Binding CheckCommand}" x:Name="send" IsVisible="true" CornerRadius="10"/>

</StackLayout>

</ContentPage.Content>

And this is the code from the viewmodel, which is the bindingcontext to the former page ^^

public string Keyword { get; set; }  <----- this is what the entry box's text is binded to.
    public int ID { get; set; }

    public ICommand CheckCommand
    {
        get
        {
            return new Command(async () =>
            {


                Checks = await _apiServices.GetCheckAsync(Keyword);
                if (_checks.Count > 0)
                {                         
                        Settings.Chk = "true";                          

                        await Application.Current.MainPage.DisplayAlert("message", "message.", "ok");                        
                 } 
                    else
                    {
                        await Application.Current.MainPage.DisplayAlert("Feil kode", "Det oppstod en feil.", "ok");
                    }
                }        
            });
        }

}

Best Answer

  • Jane_NatalieJane_Natalie ✭✭✭
    Accepted Answer

    @jezh @JohnHardman I had to make a new project and move all my code over. It now works. I think it was a problem in the obj folders or something like that.

Answers

  • Jane_NatalieJane_Natalie Member ✭✭✭

    This error is thrown with all entry boxes i try to use. And the code above worked fine before the last xamarin.forms nuget update.

  • Jane_NatalieJane_Natalie Member ✭✭✭

    The exception actually first appeared after I updated to visual studio 2019

  • jezhjezh Member, Xamarin Team Xamurai

    Could you post the steps to to reproduce this question?

  • JohnHardmanJohnHardman GBUniversity mod

    @ThankYou said:
    The exception actually first appeared after I updated to visual studio 2019

    Have you do a Clean of the entire solution, deleted bin and obj folders, restored all NuGet packages, and re-started your PC?

  • Jane_NatalieJane_Natalie Member ✭✭✭
    Accepted Answer

    @jezh @JohnHardman I had to make a new project and move all my code over. It now works. I think it was a problem in the obj folders or something like that.

Sign In or Register to comment.