小编Adr*_*osz的帖子

Xamarin.Android.你调用的对象是空的.单击按钮

当我按下任何按钮时,我得到:

System.NullReferenceException:未将对象引用设置为对象的实例.

MainActivity.cs

namespace Xamarin.Android.Pluralsight
{
    [Activity(Label = "Xamarin.Android.Pluralsight", MainLauncher = true, Icon = "@drawable/icon")]
    public class MainActivity : Activity
    {
        private Button _buttonPrevious;
        private Button _buttonNext;
        private ImageView _imageProfile;


    protected override void OnCreate(Bundle bundle)
    {
        base.OnCreate(bundle);

        SetContentView(Resource.Layout.Main);

        _buttonPrevious = FindViewById<Button>(Resource.Id.buttonPrevious);
        _buttonNext = FindViewById<Button>(Resource.Id.buttonNext);
        _imageProfile = FindViewById<ImageView>(Resource.Id.imageProfile);

        _buttonNext.Click += buttonNext_Click;
        _buttonPrevious.Click += buttonPrevious_Click;
    }

    private void buttonPrevious_Click(object sender, EventArgs e)
    {
        _imageProfile.SetImageResource(Resource.Drawable.image1);
    }

    private void buttonNext_Click(object sender, EventArgs e)
    {
        _imageProfile.SetImageResource(Resource.Drawable.image2);
    }
}
Run Code Online (Sandbox Code Playgroud)

}

Main.axml

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" …
Run Code Online (Sandbox Code Playgroud)

c# android xamarin.android xamarin

4
推荐指数
1
解决办法
7449
查看次数

标签 统计

android ×1

c# ×1

xamarin ×1

xamarin.android ×1