Forum Xamarin Xamarin.Android

System.NullReferenceException: when starting a new intent

When running the emulator a System.NullReferenceException appear.This code worked for me before but not anymore. It complains on the last four brackets in the code which doesn not help me to slove the problem.

using System;
using Android.App;
using Android.Content;
using Android.Runtime;
using Android.Views;
using Android.Widget;
using Android.OS;
using App1.Resources.values;

namespace App1
[Activity(Label = "App1", MainLauncher = true, Icon = "@drawable/icon")]
public class MainActivity : Activity

    protected override void OnCreate(Bundle bundle)

        // Set our view from the "main" layout resource

        // Get our button from the layout resource,
        // and attach an event to it
        Button button = FindViewById<Button>(Resource.Id.item);

        button.Click += delegate
            var activity2 = new Intent(this, typeof(Activity1));

    }//protect override
}//public class MainActivity : Activity

}//Namespace app1


  • MihaMarkicMihaMarkic SI ✭✭✭✭

    Why are you starting two activities at once? Besides, it might be a problem in Activity1. Did you set VS to start on all exceptions?

Sign In or Register to comment.