我刚刚开始学习Xamarin,所以我对此很陌生。我想将图像添加到按钮,但是我不断出现错误。我已经嵌入了图像,并将构建动作设置为“嵌入式资源”。我的代码很简单,因为我只是想让这部分工作:
MainPage.xaml:
<ContentPage
xmlns:controls="clr-namespace:ImageCircle.Forms.Plugin.Abstractions;assembly=ImageCircle.Forms.Plugin"
xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:local="clr-namespace:UdemyTwo"
x:Class="UdemyTwo.MainPage"
BackgroundColor="White">
<Button Image="Udemytwo.Images.clock.png"/>
</ContentPage>
MainPage.xaml.cs:
public partial class MainPage : ContentPage
{
public MainPage()
{
InitializeComponent();
}
}
MaintActivity.cs:
[Activity(Label = "UdemyTwo", Icon = "@mipmap/icon", Theme = "@style/MainTheme", MainLauncher = true, ConfigurationChanges = ConfigChanges.ScreenSize | ConfigChanges.Orientation)]
public class MainActivity : global::Xamarin.Forms.Platform.Android.FormsAppCompatActivity
{
protected override void OnCreate(Bundle bundle)
{
TabLayoutResource = Resource.Layout.Tabbar;
ToolbarResource = Resource.Layout.Toolbar;
base.OnCreate(bundle);
global::Xamarin.Forms.Forms.Init(this, bundle);
ImageCircleRenderer.Init();
LoadApplication(new App());
}
}
错误:
未处理的异常:System.NullReferenceException:对象引用 未设置为对象的实例。发生
基音出现在LoadApplication(new App());
。任何帮助将不胜感激,谢谢。