Bug 21485 - Android: Using a theme on an AndroidActivity causes NRE
Summary: Android: Using a theme on an AndroidActivity causes NRE
Status: RESOLVED DUPLICATE of bug 20459
Alias: None
Product: Forms
Classification: Xamarin
Component: Forms ()
Version: 1.2.2
Hardware: PC Windows
: Normal normal
Target Milestone: ---
Assignee: Bugzilla
URL:
Depends on:
Blocks:
 
Reported: 2014-07-21 13:09 UTC by rwakelan
Modified: 2015-02-02 01:45 UTC (History)
5 users (show)

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

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:
Status:
RESOLVED DUPLICATE of bug 20459

Description rwakelan 2014-07-21 13:09:13 UTC
If you create an Android Activity and add a Theme, it will cause a NRE to be thrown.  This theme doesn't have to do anything at all, a blank Theme style will cause this error to happen.

System.NullReferenceException: Object reference not set to an instance of an object
  at Xamarin.Forms.Platform.Android.Platform.UpdateActionBar () [0x00000] in <filename unknown>:0 
  at Xamarin.Forms.Platform.Android.Platform.SetPage (Xamarin.Forms.Page newRoot) [0x00000] in <filename unknown>:0 
  at Xamarin.Forms.Platform.Android.AndroidActivity.SetPage (Xamarin.Forms.Page page) [0x00000] in <filename unknown>:0 
  at [Activity].OnCreate (Android.OS.Bundle bundle) [0x0001f] in [Activity File]:[Line Number]

To anyone else encoutering this problem, my workaround was to create a non-AndroidActivity Activity that uses the Theme and then loads the first AndroidActivity Activity with "StartActivity" in the OnCreate handler.  This gets around the bug.

I've attached a sample reproduction of this bug.  Launch the app as is and it will show an error message for the NRE.  Comment out "Theme = "@style/Theme.Splash"," in the Activity header and the error will go away.  Theme.Splash is an empty theme, it does nothing.  This happens regardless of what the Theme does.
Comment 1 Eric Maupin 2014-07-22 16:27:44 UTC
Currently we only support themes that contain action bars. We're working on addressing this, but in the mean time you will have to limit which theme you select.
Comment 2 Jason Smith [MSFT] 2015-02-02 01:45:28 UTC

*** This bug has been marked as a duplicate of bug 20459 ***