Xamarin FindViewById returns null

后端 未结 3 637
有刺的猬
有刺的猬 2020-12-20 15:38

Hi guys I need a little advice. I trying to made an android app using Xamarin so C#. I made two layouts and in each one of them I made tow buttons to navigate between them.I

3条回答
  •  情书的邮戳
    2020-12-20 16:39

    You're getting a NullReferenceException because this code:

    FindViewById

--OR--

  • 2 - that Button isn't defined on the Main layout and therefore it isn't part of the Activity's current view. Therefore the FindViewById() method can't find it. Your intended approach to switch screens isn't supported on Android.

    Which leads to a longer explanation about the Correct way to "switch screens" on Android: navigating between simple activities

Try one of these solutions.

提交回复
热议问题