Forum Xamarin.Android

I am getting an "Object reference not set to an instance of an object."

This happens on the MainActivity when i call a button click event.

public class MainActivity : AppCompatActivity
protected override void OnCreate(Bundle savedInstanceState)

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

        Button btnLogin = this.FindViewById<Button>(Resource.Id.btnGotoLogin);
        btnLogin.Click += (object sender, EventArgs e) =>
            Intent intent = new Intent(this, typeof(LoginActivity));

        Button btnRegister = this.FindViewById<Button>(Resource.Id.btnGotoReg2);
        btnRegister.Click += (object sender, EventArgs e) =>
            Intent intent = new Intent(this, typeof(RegisterActivity));


  • AnandmauryaAnandmaurya INMember ✭✭
    edited June 2019

    @ndzalama Can you explain more. I think LoginActivity and RegisterActivity to be set as Activity like below .

    [Activity(Label = "LoginActivity", MainLauncher = false, Theme = "@style/MyTheme")]
    public class LoginActivity : AppCompatActivity

    Theme is optional.

  • YelinzhYelinzh Member, Xamarin Team Xamurai

    There may be something wrong with the code in LoginActivity or RegisterActivity?
    Which activity occured the error when calling StartActivity(). Please post the code of the activity.

Sign In or Register to comment.