FindViewById<Button> is returning Null RRS feed

  • Question

  • User366960 posted

    So I am adding new button to my app but when FindViewById is called it returns null and app crashes. In my .cs file I have following function:

    void fooUIButtonHandler() { var fooUIButton = FindViewById

    Tuesday, May 8, 2018 4:39 PM

All replies

  • User99156 posted

    @Ika777 Change your code to

    csharp var fooUIButton = FindViewById<Button>(Resource.Id.fooUIButton);


    csharp var fooUIButton = (Button) FindViewById(Resource.Id.fooUIButton);

    Tuesday, May 8, 2018 6:29 PM
  • User366960 posted

    @RofiqSetiawan I am sorry I have <Button> after FindViewById, got removed when i was posting it: so here is correct version: var fooUIButton = FindViewById<Button>(Resource.Id.fooUIButton);
    Still getting NPE

    Tuesday, May 8, 2018 6:37 PM
  • User99156 posted

    Hmm... maybe you can recheck these things:

    • Your fooUIButton is inside FooDocumentCreation.axml layout
    • You've called SetContentView(Resource.Layout.FooDocumentCreation); before FindViewById
    Tuesday, May 8, 2018 6:53 PM
  • User356437 posted

    can you share your code in cs file?

    Wednesday, May 9, 2018 6:44 AM
  • User366960 posted

    @RofiqSetiawan Thank you, my bad, I misspelled button name in my .axml file :s , everything works.

    Wednesday, May 9, 2018 8:57 PM