AndroidGameWindow.SetDisplayOrientation NullReferenceException

Ram*_*say 17 c# android xamarin.android monogame

我使用MonoGame和Xamarin为Android开发了一款游戏.我将BugSense合并到其中并迅速开始获得以下异常堆栈跟踪:

System.NullReferenceException: Object reference not set to an instance of an object
at Microsoft.Xna.Framework.AndroidGameWindow.SetDisplayOrientation (Microsoft.Xna.Framework.DisplayOrientation) <0x001c4>
at Microsoft.Xna.Framework.AndroidGameWindow.SetOrientation (Microsoft.Xna.Framework.DisplayOrientation,bool) <0x00097>
at Microsoft.Xna.Framework.OrientationListener.OnOrientationChanged (int) <0x001c7>
at Android.Views.OrientationEventListener.n_OnOrientationChanged_I (intptr,intptr,int) <0x0003f>
at (wrapper dynamic-method) object.ed9d7c7c-f3e6-4d7a-9249-1a139a251aed (intptr,intptr,int) <0x00043>
Run Code Online (Sandbox Code Playgroud)

这就是我的活动设置方式:

[Activity(Label = "My Cool Game"
        , MainLauncher = true
        , Icon = "@drawable/icon"
        , Theme = "@style/Theme.Splash"
        , AlwaysRetainTaskState = true
        , LaunchMode = Android.Content.PM.LaunchMode.SingleTask
        , ScreenOrientation = ScreenOrientation.Portrait
        , ConfigurationChanges = ConfigChanges.Orientation | ConfigChanges.Keyboard | ConfigChanges.KeyboardHidden)]
Run Code Online (Sandbox Code Playgroud)

在游戏构造函数中,我有以下内容:

public Game1()
{
    _graphics = new GraphicsDeviceManager(this);
    _graphics.PreferredBackBufferFormat = SurfaceFormat.Color;
    _graphics.IsFullScreen = true;
    _graphics.SupportedOrientations = DisplayOrientation.Portrait | DisplayOrientation.PortraitDown;
    _graphics.ApplyChanges();
}
Run Code Online (Sandbox Code Playgroud)

该项目设置为针对v2.3进行编译.我没有任何与我的测试设备上的方向有关的问题所以我不确定是什么导致了这个例外,因此我无法解决它.

Sol*_*man 1

在处理不同的项目之前,我遇到过这个空引用异常。您必须原谅我对您的游戏特定领域的无知,但让我向您解释这意味着什么,也许它会帮助您解决这个问题。此异常意味着内存中没有可供系统处理的特定类型的对象。必须使用 new 关键字或其他方式创建该对象的实例,才能将其识别为内存中的有效对象。

从阅读上面的错误消息来看,似乎需要一个对象来初始化显示方向。在您的构造函数或活动设置中,我没有看到任何为显示方向创建任何对象的内容。因此该对象不存在于内存中,因此它为空。