![](/img/trans.png)
[英]An unhandled exception occured xamarin.forms when i click a button in xamarin
[英]An unhandled exception on button click xamarin android
單擊按鈕時,我遇到了未處理的異常錯誤,該按鈕應引導我進行下一個活動。
protected override void OnCreate(Bundle bundle)
{
base.OnCreate(bundle);
SetContentView(Resource.Layout.main);
Button contactbtn = FindViewById<Button>(Resource.Id.button4);
contactbtn.Click += Contactbtn_Click;
}
private void Contactbtn_Click(object sender, EventArgs e)
{
// throw new NotImplementedException();
StartActivity(typeof(Activity1));
}
發生未處理的異常。
問題應該出在 Activity1 中。 此問題的一種可能性是您在使用FindViewById
時沒有為 Activity 設置布局(假設layout1
是Activity1
的布局):
SetContentView(Resource.Layout.layout1);
如果你沒有這個, FindViewById
將總是返回null
。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.