启动Xamarin Droid App时出现System.NullReferenceException

时间:2017-09-29 15:57:45

标签: xamarin xamarin.forms xamarin.android mvvmcross

我正在使用MVVM Cross,Mvvm Cross Forms,Xamarin Forms和Grail KIT开发应用程序。在IOS中它完美无缺。但是当我在Android上启动它时,我得到一个没有痕迹的错误,我不知道如何解决它。

执行 OnStart 方法后。发生此异常:

enter image description here

enter image description here

逐步执行调试器不允许我超越这种方法。

这是 MvxFormsApplication 的代码。

public partial class App : MvxFormsApplication
    {

        private void ConfigLocale()
        {

            if (Device.RuntimePlatform == Device.iOS || Device.RuntimePlatform == Device.Android )
            {
                Debug.WriteLine("Get Culture Info ...");
                var ci = DependencyService.Get<ILocalize>().GetCurrentCultureInfo();
                Debug.WriteLine(ci.ToString());
                AppResources.Culture = ci; // set the RESX for resource localization
                DependencyService.Get<ILocalize>().SetLocale(ci); // set the Thread for locale-aware methods
            }
        }

        public App()
        {
            ConfigLocale();
            InitializeComponent();
        }

        void OnAuthenticatedUserMessage(AuthenticatedUserMessage authenticatedUserMessage)
        {

            Debug.WriteLine("OnAuthenticatedUserMessage ...");

            var deviceGroupsService = Mvx.Resolve<IDeviceGroupsService>();
            // save token
            deviceGroupsService.saveDevice(CrossDeviceInfo.Current.Id, Settings.FcmToken).Subscribe(device => {
                Debug.WriteLine(String.Format("Device Saved: {0}", device.ToString()));
            });

        }


        void OnExceptionOcurredMessage(ExceptionOcurredMessage exceptionOcurredMessage) 
        {
            Debug.WriteLine("OnExceptionOcurredMessage ...");

            var userDialogs = Mvx.Resolve<IUserDialogs>();

            userDialogs.ShowError(AppResources.Global_ErrorOcurred);

            if (exceptionOcurredMessage.Ex != null)
                exceptionOcurredMessage.Ex.Track();

        }

        protected override void OnStart()
        {

            Debug.WriteLine("Forms App OnStart ...");
            var messenger = Mvx.Resolve<IMvxMessenger>();
            // subscribe to Authenticated User Message
            messenger.Subscribe<AuthenticatedUserMessage>(OnAuthenticatedUserMessage);
            // subscribe to Exception Ocurred Message
            messenger.Subscribe<ExceptionOcurredMessage>(OnExceptionOcurredMessage);

            //Handling FCM Token
            CrossFirebasePushNotification.Current.OnTokenRefresh += (s, p) =>
            {
                Debug.WriteLine($"TOKEN REC: {p.Token}");
                Settings.FcmToken = p.Token;
            };
            Debug.WriteLine($"TOKEN: {CrossFirebasePushNotification.Current.Token}");
            Settings.FcmToken = CrossFirebasePushNotification.Current.Token;

        }

    }
}

应用程序以我在下面公开的SplashScreen开始:

using System;
using Android.App;
using Android.Content.PM;
using MvvmCross.Droid.Views;
using MvvmCross.Forms.Droid;
using Xamarin.Forms;

namespace Bullytect.Droid
{
    [Activity(
        Name = "com.usal.bisite.bulltect.SplashScreen",
        Label = "Bulltect"
        , MainLauncher = true
        , Icon = "@mipmap/ic_launcher"
        , Theme = "@style/Theme.Splash"
        , NoHistory = true
        , ScreenOrientation = ScreenOrientation.Portrait)]
    public class SplashScreen : MvxSplashScreenActivity
    {

        public override void InitializationComplete()
        {
            StartActivity(typeof(MvxFormsApplicationActivity));
        }

        protected override void OnCreate(Android.OS.Bundle bundle)
        {
            Forms.Init(this, bundle);
            // Leverage controls' StyleId attrib. to Xamarin.UITest
            Forms.ViewInitialized += (object sender, ViewInitializedEventArgs e) => {
                if (!string.IsNullOrWhiteSpace(e.View.StyleId))
                {
                    e.NativeView.ContentDescription = e.View.StyleId;
                }
            };

            base.OnCreate(bundle);
        }
    }
}

然后,应用程序应用程序执行活动 MvxFormsApplicationActivity

namespace Bullytect.Droid
{


    [Activity(
        Name = "com.usal.bisite.bulltect.MvxFormsApplicationActivity",
        Label = "bulltect",
        Icon = "@mipmap/ic_launcher",
        Theme = "@style/AppTheme",
        MainLauncher = false,
        LaunchMode = LaunchMode.SingleTask,
        ScreenOrientation = ScreenOrientation.Portrait
    )]
    public class MvxFormsApplicationActivity : FormsAppCompatActivity
    {
        protected override void OnCreate(Bundle bundle)
        {

            try
            {
                ToolbarResource = Resource.Layout.Toolbar;
                TabLayoutResource = Resource.Layout.Tabs;

                base.OnCreate(bundle);

                Forms.Init(this, bundle);
                PullToRefreshLayoutRenderer.Init();
                XFGloss.Droid.Library.Init(this, bundle);
                //Initializing FFImageLoading
                CachedImageRenderer.Init();
                UserDialogs.Init(this);

                GrialKit.Init(this, "Bullytect.Droid.GrialLicense");

                FormsHelper.ForceLoadingAssemblyContainingType(typeof(UXDivers.Effects.Effects));


                var formsPresenter = (MvxFormsPagePresenter)Mvx.Resolve<IMvxAndroidViewPresenter>();
                LoadApplication(formsPresenter.FormsApplication);


                //FirebasePushNotificationManager.ProcessIntent(Intent);

            }
            catch (Exception e)
            {

                System.Diagnostics.Debug.WriteLine("**BullTect LAUNCH EXCEPTION**\n\n" + e);
            }


        }

        public override void OnConfigurationChanged(Android.Content.Res.Configuration newConfig)
        {
            base.OnConfigurationChanged(newConfig);

            DeviceOrientationLocator.NotifyOrientationChanged();
        }
    }
}

这些是我安装的所有软件包:

enter image description here enter image description here

enter image description here

enter image description here

希望有人可以帮助我。

0 个答案:

没有答案