Bug 30935 - NullReferenceException in ViewRenderer<TView, TNativeView> (Xamarin.Forms.Platform.Android)
Summary: NullReferenceException in ViewRenderer<TView, TNativeView> (Xamarin.Forms.Pla...
Alias: None
Product: Forms
Classification: Xamarin
Component: Android ()
Version: 1.4.2
Hardware: PC Windows
: High normal
Target Milestone: ---
Assignee: Rui Marinho
Depends on:
Reported: 2015-06-09 06:28 UTC by patrickg
Modified: 2015-06-16 07:23 UTC (History)
3 users (show)

Tags: ac page
Is this bug a regression?: ---
Last known good build:

Test case (483.18 KB, application/octet-stream)
2015-06-09 16:34 UTC, Sergey Komisarchik

Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.

Please create a new report on Developer Community or GitHub with your current version information, steps to reproduce, and relevant error messages or log files if you are hitting an issue that looks similar to this resolved bug and you do not yet see a matching new report.

Related Links:

Description patrickg 2015-06-09 06:28:49 UTC
There's a bug in private method  Android.Views.View.IOnFocusChangeListener.OnFocusChange(Android.Views.View v, bool hasFocus)

I have noticed that in the for loop the variable parent can be null at times causing a NullReferenceException.

        for (Element parent = this.Element.Parent; !(parent is Page); parent = parent.Parent)

Only adding a null check would fix it I think: 
        for (Element parent = this.Element.Parent; parent != null && !(parent is Page); parent = parent.Parent)
Comment 1 Rui Marinho 2015-06-09 06:59:57 UTC
Thank you for taking the time to submit the bug. We tried to reproduce the issue you reported but were unable given the description. If you could please attach a reproduction to the bug by starting with a clean Xamarin.Forms project and adding just the code necessary to demonstrate the issue we would very much appreciate it.

Warm regards,
Xamarin Forms Team
Comment 2 Sergey Komisarchik 2015-06-09 16:31:58 UTC
I confirm this. This little sample fails:

public class App : Application
    public App()
        var page = new ContentPage();
        var entry = new Entry();

        page.Content = entry;
        page.Appearing += (sender, args) =>
                page.Content = null;

        this.MainPage = page;
Comment 3 Sergey Komisarchik 2015-06-09 16:34:36 UTC
Created attachment 11540 [details]
Test case
Comment 4 patrickg 2015-06-09 19:15:19 UTC
See sergeys commenta and repro
Comment 5 Rui Marinho 2015-06-15 11:29:22 UTC
Should be fixed in 1.4.3 final.
Comment 6 Parmendra Kumar 2015-06-16 07:23:43 UTC
I have checked this issue with Xamarin.Forms. and I am not getting any exception.

Hence closing this issue.