Quantcast
Channel: Xamarin.Forms — Xamarin Community Forums
Viewing all articles
Browse latest Browse all 77050

You MUST call Xamarin.Forms.Init(); prior to using it

$
0
0

In my app.xaml.cs I create a new page.

 public App()
  {
      InitializeComponent();
      MainPage = new NavigationPage(new WrapLayoutPage());
  }

This page calls a static class, which uses the DependencyService to perform some tasks. This throws me a TypeInitializationException with the InnerException "You MUST call Xamarin.Forms.Init(); prior to using it". Normally it would be pretty clear, but since I call this in my MainActivity in the android project, I really don't know what I'm supposed to do.

    [Activity(Label = "FrameworkForms", Icon = "@drawable/icon", ConfigurationChanges = ConfigChanges.ScreenSize | ConfigChanges.Orientation, Theme = "@android:style/Theme.Material.Light")]
    public class MainActivity : global::Xamarin.Forms.Platform.Android.FormsApplicationActivity
    {
        protected override void OnCreate(Bundle bundle)
        {
            base.OnCreate(bundle);
            Xamarin.Forms.Forms.Init(this, bundle);
            App.ScreenWidth = (double)(Resources.DisplayMetrics.WidthPixels / Resources.DisplayMetrics.Density);
            LoadApplication(new App());
        }
    }

Viewing all articles
Browse latest Browse all 77050

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>