V 1.2.1 NullReferenceException at Platform.Android.Platform.SetActionBarTextColor

ChaseFlorellChaseFlorell CAInsider, University mod
edited July 2014 in Xamarin.Forms

I figured this needed it's own thread.

In my app I have a MasterDetailPage, and the Detail page is a ContentPage wrapped in a NavigationPage.

When I load the app, it crashes immediately with

07-15 09:31:47.143 I/MonoDroid(30762): UNHANDLED EXCEPTION: System.NullReferenceException: Object reference not set to an instance of an object
07-15 09:31:47.143 I/MonoDroid(30762): at Xamarin.Forms.Platform.Android.Platform.SetActionBarTextColor () [0x00000] in :0
07-15 09:31:47.143 I/MonoDroid(30762): at Xamarin.Forms.Platform.Android.Platform.UpdateActionBarTextColor () [0x00000] in :0
07-15 09:31:47.143 I/MonoDroid(30762): at Xamarin.Forms.Platform.Android.Platform.set_CurrentNavigationPage (Xamarin.Forms.NavigationPage value) [0x00000] in :0
07-15 09:31:47.143 I/MonoDroid(30762): at Xamarin.Forms.Platform.Android.Platform.UpdateActionBar () [0x00000] in :0
07-15 09:31:47.143 I/MonoDroid(30762): at Xamarin.Forms.Platform.Android.Platform+d__8.MoveNext () [0x00000] in :0
07-15 09:31:47.143 I/MonoDroid(30762): --- End of stack trace from previous location where exception was thrown ---
07-15 09:31:47.143 I/MonoDroid(30762): at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw () [0x00000] in :0
07-15 09:31:47.143 I/MonoDroid(30762): at System.Runtime.CompilerServices.TaskAwaiter.GetResult () [0x00000] in :0
07-15 09:31:47.143 I/MonoDroid(30762): at FutureState.AppCore.Pages.MainPage+d__1.MoveNext () [0x0007c] in c:\Users\Chase\Projects\mobi.futurestate.breathingroom\FutureState.AppCore\Pages\MainPage.cs:39
Unhandled Exception:

This is a Show Stopper, unless we can come up with a viable work-around.

For me, there's other "Show Stoppers" in v1.1.1 that I'm desparately trying to get the new version working in hopes that it fixes some ListView items that I can't seem to work-around.

Posts

  • EricMaupinEricMaupin USXamarin Team Xamurai

    We know. In the meantime, an awful work around is to ensure that you have a NavigationPage.

  • ChaseFlorellChaseFlorell CAInsider, University mod

    @ermau I'm pretty sure I do have a navigation page... am I doing this incorrectly? It just crept in after the last update.

    My App does this

        public static INavigation Navigation { get; set; }
        public static Page GetMainPage(IContainer container)
        {
            Container = container;
    
            RegisterCurrentUser(Container.Resolve<UserModel>());
            RunMigrations();
            RegisterCurrentUser();
    
            var rootPage = Container.Resolve<MainPage>();
            return rootPage;
        }
    

    And the MainPage

        public MainPage()
        {
            Title = Strings.app_title;
            var master = new MainMenu(OnAfterDeauthenticated, OnToggleRequest());
            var detail = new NavigationPage(new ModulePage { Title = Strings.app_title });
    
            if (App.Navigation == null)
            {
                App.Navigation = detail.Navigation;
            }
    
            Master = master;
            Detail = detail;
        }
    
  • ChaseFlorellChaseFlorell CAInsider, University mod

    Ok, I get it, I have to wrap EVERYTHING in a NavigationPage... you're right, it's awful..._ hot fix needed_ :)

    Essentially my AuthPage is a TabbedPage... each Tab needed to also be wrapped in a NavigationPage... this shows the back arrow at the top... and I've prevented "back" in Android so that the user can't get back into the app from the login page... not sure how this behavior will affect iOS users.

  • FrTerstappenFrTerstappen DEMember

    Need this fix also asap.
    Released my ios version last week. Now i cant release my android version.

  • MihaMarkicMihaMarkic SI ✭✭✭✭

    FYI it crashes even with a new project created from Blank App template. I guess the other solution would be to downgrade Forms for the time being...

  • MihaMarkicMihaMarkic SI ✭✭✭✭
    edited July 2014

    In VS one would open Package Manager Console (Powershell) and type these guys:

    Get-Project -All | Uninstall-Package Xamarin.Forms Get-Project -All | Install-Package Xamarin.Forms -version 1.1.1.6206

    Version 1.1.1.6206 is the newest I've found that works. Note, the above commands will install Forms to all projects, if you want/need you can add manually to each project instead, i.e. select Default Project and then:

    Install-Package Xamarin.Forms -version 1.1.1.6206

    You might also want to prevent accidental updating by adding

    allowedVersions="[1.1, 1.1.1.6206]"

    parameter to Xamarin.Forms package node in each project's package.conifg.

    HTH

  • RiccardoMoschettiItalyRiccardoMoschettiItaly USMember
    edited July 2014

    +1
    the Blank apps template (both PCL and Shared) crash at runtime (with Genymotion) if I upgrade the nuget packages to 1.2.1.6229 (forms) and 20.0.0 (Xamarin.Android.Support)

    I launch the app and

    System.Diagnostics.Debugger.Mono_UnhandledException (ex={System.NullReferenceException: Object reference not set to an instance of an object
    at Xamarin.Forms.Platform.Android.Platform.SetActionBarTextColor () <IL 0x00006, 0x00065>
    at Xamarin.Forms.Platform.Android.Platform.UpdateActionBarTextColor () <IL 0x00001, 0x00027>
    at Xamarin.Forms.Platform.Android.Platform.OnLayout (bool,int,int,int,int) <IL 0x00004, 0x00053>
    at Xamarin.Forms.Platform.Android.PlatformRenderer.OnLayout (bool,int,int,int,int) <IL 0x0001b, 0x00083>
    at Android.Views.ViewGroup.n_OnLayout_ZIIII (intptr,intptr,bool,int,int,int,int) [0x00009] in /Users/builder/data/lanes/monodroid-mlion-monodroid-4.12-series/163212a9/source/monodroid/src/Mono.Android/platforms/android-15/src/generated/Android.Views.ViewGroup.cs:2869
    at (wrapper dynamic-method) object.d360dba8-71db-4853-8a04-6cde750afac7 (intptr,intptr,bool,int,int,int,int) <IL 0x0002f, 0x0004b>
    }) in 
    
  • ShibaKanekiShibaKaneki USMember

    I got the same issue and I solved it after reading @ermau‌ comment.
    On my side, the problem was that my application was first displaying a Splashscreen and then called another Activity that will display the rest of my app. This MainActivity was doing a SetPage(new TestPage()). I changed it to SetPage(new NavigationPage(new TestPage())) and it worked.

  • FrTerstappenFrTerstappen DEMember

    @ChaseFlorell This gives me a error on Android. It says that Only one NavigationPage is allowed on Screen for Android.
    How did you solve this? Could you post your code generating the site?

  • AlanTonissonAlanTonisson AUMember ✭✭

    I could wrap a single tabbed page in a NavigationPage. That worked except it puts a back link icon in the action bar which makes my app look unprofessional.

    I got stumped after that because I need to use PushModalAsync to display a login page.

    loginButton.Clicked += async delegate
    {
    await Navigation.PushModalAsync(new LoginPage(settings));
    //await Navigation.PushModalAsync(new ContentPage { Title = "Page Title" });
    };

    That throws a null reference exception (the commented out code does the same):

    System.Diagnostics.Debugger.Mono_UnhandledException_internal () in 
    System.Diagnostics.Debugger.Mono_UnhandledException (ex=) in 
    object.2e5f5507-02fd-49f8-a816-a7a1ffcf57e6 (Parameters=) in 
    System.Runtime.CompilerServices.AsyncVoidMethodBuilder.AnonymousMethod__0 (Parameters=) in 
    Android.App.SyncContext.Post.AnonymousMethod__0 (Parameters=) in /Users/builder/data/lanes/monodroid-mlion-monodroid-4.12-series/163212a9/source/monodroid/src/Mono.Android/src/Android.App/SyncContext.cs:18
    Java.Lang.Thread.RunnableImplementor.Run (Parameters=) in /Users/builder/data/lanes/monodroid-mlion-monodroid-4.12-series/163212a9/source/monodroid/src/Mono.Android/src/Java.Lang/Thread.cs:36
    Java.Lang.IRunnableInvoker.n_Run (Parameters=) in /Users/builder/data/lanes/monodroid-mlion-monodroid-4.12-series/163212a9/source/monodroid/src/Mono.Android/platforms/android-19/src/generated/Java.Lang.IRunnable.cs:71
    object.2e5f5507-02fd-49f8-a816-a7a1ffcf57e6 (Parameters=) in 
    

    Wrapping it in a NavigationPage does not work either.

  • AlanTonissonAlanTonisson AUMember ✭✭

    The prerelease of Xamarin.Forms 1.2.2 seems to solve most of my problems. Thanks!

  • MartinKramerMartinKramer ATMember

    Had the same problem with the NullReferenceException and Alan's tip worked for me - it seems this is fixed in the pre-release.

    Take care,
    Martin

Sign In or Register to comment.