Quantcast
Channel: Xamarin.Forms — Xamarin Community Forums
Viewing all articles
Browse latest Browse all 89864

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

$
0
0

"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 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");
                    }
                }        
            });
        }

}


Viewing all articles
Browse latest Browse all 89864

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>