Bug 32555 - I add a Activity with create by 'LoadApplication(application)' to TabHost, then I get a 'System.NullReferenceException'.
Summary: I add a Activity with create by 'LoadApplication(application)' to TabHost, th...
Alias: None
Product: Forms
Classification: Xamarin
Component: Forms ()
Version: unspecified
Hardware: All All
: --- normal
Target Milestone: ---
Assignee: Bugzilla
Depends on:
Reported: 2015-07-28 22:53 UTC by changyu
Modified: 2015-08-04 04:14 UTC (History)
4 users (show)

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

This is my main code. (4.80 MB, application/octet-stream)
2015-07-29 21:09 UTC, changyu
new attachment (4.34 MB, application/octet-stream)
2015-07-31 15:04 UTC, changyu

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 changyu 2015-07-28 22:53:54 UTC
I want to use a 'TabActivity', and use some 'Forms Page' as its child Activity.
I create a 'TabActivity', and add some child 'Activity' with Create by 'LoadApplication(application)'.
Then I get a exception like this:
------------------------Exception START-----------------------------------
System.NullReferenceException: Object reference not set to an instance of an object
  at Xamarin.Forms.Platform.Android.Platform.UpdateActionBarBackgroundColor () [0x00010] in <filename unknown>:0 
  at Xamarin.Forms.Platform.Android.Platform.set_CurrentNavigationPage (Xamarin.Forms.NavigationPage value) [0x000f1] in <filename unknown>:0 
  at Xamarin.Forms.Platform.Android.Platform.UpdateActionBar () [0x00068] in <filename unknown>:0 
  at Xamarin.Forms.Platform.Android.Platform.SetPage (Xamarin.Forms.Page newRoot) [0x000bf] in <filename unknown>:0 
  at Xamarin.Forms.Platform.Android.FormsApplicationActivity.InternalSetPage (Xamarin.Forms.Page page) [0x000b7] in <filename unknown>:0 
  at Xamarin.Forms.Platform.Android.FormsApplicationActivity.SetMainPage () [0x0000c] in <filename unknown>:0 
  at Xamarin.Forms.Platform.Android.FormsApplicationActivity.LoadApplication (Xamarin.Forms.Application application) [0x0002d] in <filename unknown>:0 
  at App_Tabbed.Droid.MainActivity.OnCreate (Android.OS.Bundle bundle) [0x00011] in c:\Users\admin\Desktop\App_Tabbed\App_Tabbed\App_Tabbed.Droid\MainActivity.cs:24 
  at Android.App.Activity.n_OnCreate_Landroid_os_Bundle_ (IntPtr jnienv, IntPtr native__this, IntPtr native_savedInstanceState) [0x00011] in /Users/builder/data/lanes/1879/5f55a9ef/source/monodroid/src/Mono.Android/platforms/android-21/src/generated/Android.App.Activity.cs:2707 
  at (wrapper dynamic-method) object:c33eda0c-fc1f-4527-afd2-7fdd4a53b699 (intptr,intptr,intptr)
--- End of stack trace from previous location where exception was thrown ---
  at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw () [0x0000b] in <filename unknown>:0 
  at Android.Runtime.JNIEnv.CallVoidMethod (IntPtr jobject, IntPtr jmethod, Android.Runtime.JValue* parms) [0x00063] in /Users/builder/data/lanes/1879/5f55a9ef/source/monodroid/src/Mono.Android/src/Runtime/JNIEnv.g.cs:571 
  at Android.Widget.TabHost.AddTab (Android.Widget.TabSpec tabSpec) [0x0005a] in /Users/builder/data/lanes/1879/5f55a9ef/source/monodroid/src/Mono.Android/platforms/android-21/src/generated/Android.Widget.TabHost.cs:943 
  at App_Tabbed.Droid.MainTab.AddSpec () [0x00001] in c:\Users\admin\Desktop\App_Tabbed\App_Tabbed\App_Tabbed.Droid\MainTab.cs:52 
  at App_Tabbed.Droid.MainTab.OnCreate (Android.OS.Bundle bundle) [0x0003f] in c:\Users\admin\Desktop\App_Tabbed\App_Tabbed\App_Tabbed.Droid\MainTab.cs:35
------------------------Exception END-----------------------------------

My primary code like this:
------------------------Code Start-------------------------
    public class App : Application
        public App()
            MainPage = new NavigationPage(new ScrollPage());

    [Activity(Label = "MainActivity")]
    public class MainActivity : global::Xamarin.Forms.Platform.Android.FormsApplicationActivity
        protected override void OnCreate(Bundle bundle)

            global::Xamarin.Forms.Forms.Init(this, bundle);

            LoadApplication(new App());

[Activity(Label = "App_Tabbed", Icon = "@drawable/icon", MainLauncher = true, ConfigurationChanges = ConfigChanges.ScreenSize | ConfigChanges.Orientation)]
    public class MainTab : TabActivity, Android.Widget.RadioGroup.IOnCheckedChangeListener 

        private TabHost tabHost;

        protected override void OnCreate(Bundle bundle)

                tabHost = TabHost;
                LocalActivityManager groupActivity = new LocalActivityManager(this, false);
            catch (Exception e)
                var msg = e.Message;

        private void AddSpec() 
            tabHost.AddTab(this.BuildTagSpec("tab_home", "首页", Resource.Drawable.icon, new Intent(this, typeof(MainActivity))));
            tabHost.AddTab(this.BuildTagSpec("tab_shop", "店铺", Resource.Drawable.icon, new Intent(this, typeof(MainActivity))));
            tabHost.AddTab(this.BuildTagSpec("tab_message", "消息", Resource.Drawable.icon, new Intent(this, typeof(MainActivity))));
            tabHost.AddTab(this.BuildTagSpec("tab_more", "更多", Resource.Drawable.icon, new Intent(this, typeof(MainActivity))));

        private TabHost.TabSpec BuildTagSpec(String tagName, int tagLable, int icon, Intent content)
            return tabHost.NewTabSpec(tagName)
                .SetIndicator(Resources.GetString(tagLable), Resources.GetDrawable(icon))
        private TabHost.TabSpec BuildTagSpec(String tagName, string tagLable, int icon, Intent content)
            return tabHost.NewTabSpec(tagName)
                .SetIndicator(tagLable, Resources.GetDrawable(icon))

------------------------Code End---------------------------

The bug troubled me a long time. TabbedPage of Forms is too hard to build a beautiful UI. So I have to adopt the top solution.
Any idea?
Comment 1 Chris King 2015-07-29 12:46:36 UTC
Thanks for submitting this bug. We give priority to bugs with attached reproductions so if you could you please zip up your project and upload it as an attachment to the bug that would expedite resolution of your issue.

Warm regards,
Comment 2 changyu 2015-07-29 21:09:43 UTC
Created attachment 12292 [details]
This is my main code.
Comment 3 changyu 2015-07-29 21:10:11 UTC
Comment 4 Chris King 2015-07-31 13:38:58 UTC
Changyu, thanks for uploading your app. I'm able to launch it and tap on UI elements on iOS and Android without seeing any exceptions. Could you attach a screen capture showing the issue on a simulator?

Warm regards,
Comment 5 changyu 2015-07-31 15:04:44 UTC
Created attachment 12324 [details]
new attachment

new attachment
Comment 6 changyu 2015-07-31 15:12:52 UTC
sorry for my mistake, the privious app exception been caught by try catch, the new app uploaded removed the try catch, so you can see the crash.