0

When trying to create a simple Xamarin app, on debugging I will immediately get a dialog box quoting:

Object Reference not set to an instance of an object

Nothing appears in my error list.

Can anyone give me tips on where I am going wrong?

Many thanks,

Gary

MainPage.xaml

<xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:local="clr-namespace:XamarinApp1"
x:Class="XamarinApp1.MainPage">

<StackLayout>

<!-- Place new controls here -->
<Label Text="Welcome to Xamarin.Forms!" 
HorizontalOptions="Center"
VerticalOptions="CenterAndExpand" />
<Button Text="Click Me" Clicked="Button_Clicked" />
</StackLayout>

</ContentPage>

MainPage.xaml.cs

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Xamarin.Forms;

namespace XamarinApp1

{
public partial class MainPage : ContentPage
{
public MainPage()
{
InitializeComponent();
}
int count = 0;

private void Button_Clicked(object sender, EventArgs e)
{
count++;
((Button)sender).Text = $"You clicked {count} times.";

}
}

app.xaml.cs

using System;
using Xamarin.Forms;
using Xamarin.Forms.Xaml;

[assembly: XamlCompilation(XamlCompilationOptions.Compile)]
namespace XamarinApp1
{
public partial class App : Application
{
public App()
{
InitializeComponent();
MainPage = new MainPage();
}
protected override void OnStart()
{
// Handle when your app starts
}
protected override void OnSleep()
{
// Handle when your app sleeps
}
protected override void OnResume()
{
// Handle when your app resumes
}
}  
}

Error

soulshined
  • 9,612
  • 5
  • 44
  • 79
badgerless
  • 45
  • 8

0 Answers0