C# 4.0 ';System.NullReferenceException';在定义对象XNA C时#

C# 4.0 ';System.NullReferenceException';在定义对象XNA C时#,c#-4.0,nullreferenceexception,xna-4.0,C# 4.0,Nullreferenceexception,Xna 4.0,我最近一直在尝试制作一个游戏,并决定从头开始。然而,我很快就遇到了一个错误,这在我的游戏的前一个阶段不是问题。 我和我的朋友讨论了一些可能导致错误的想法,但是我们没有找到 显然,当我尝试使用不同的类(UI.UILoader)加载对象时,它以某种方式创建了一个错误。主要类如下所示: namespace WindowsGame1.Classes { public static Game1 instance; GraphicsDeviceManager graphics;

我最近一直在尝试制作一个游戏,并决定从头开始。然而,我很快就遇到了一个错误,这在我的游戏的前一个阶段不是问题。 我和我的朋友讨论了一些可能导致错误的想法,但是我们没有找到

显然,当我尝试使用不同的类(UI.UILoader)加载对象时,它以某种方式创建了一个错误。主要类如下所示:

namespace WindowsGame1.Classes
{    
    public static Game1 instance;
    GraphicsDeviceManager graphics;
    SpriteBatch spriteBatch;
    public MouseState mouseState;
    public KeyboardState keyState;
    public SpriteFont debugFont;
    Instance inst;
    public Game1()
    {
        graphics = new GraphicsDeviceManager(this);
        Content.RootDirectory = "Content";
    }

    protected override void LoadContent()
    {
        // Create a new SpriteBatch, which can be used to draw textures.
        spriteBatch = new SpriteBatch(GraphicsDevice);
        debugFont = Content.Load<SpriteFont>("debugFont");
        inst.Load();
        UI.UILoader.Load();
        // TODO: use this.Content to load your game content here
    }
namespace WindowsGame1.class
{    
公共静态Game1实例;
图形管理器图形;
SpriteBatch SpriteBatch;
公共屋;;
公用键盘状态键状态;
公共字体;
实例研究所;
公共游戏1()
{
graphics=新的GraphicsDeviceManager(此);
Content.RootDirectory=“Content”;
}
受保护的覆盖void LoadContent()
{
//创建一个新的SpriteBatch,可用于绘制纹理。
spriteBatch=新spriteBatch(图形设备);
debugFont=Content.Load(“debugFont”);
仪器负荷();
UI.UILoader.Load();
//TODO:使用此.Content在此处加载游戏内容
}
可以在下面看到类UILoader,它尝试使用Texture2D加载两个纹理。但是,当它尝试加载第一个纹理时,我收到“System.NullReferenceException”错误

namespace WindowsGame1.Classes.UI
{
    public static class UILoader
    {
        public static Texture2D cursorTexture;
        public static Texture2D buttonTexture;

        public static void Load()
        {
            cursorTexture = Game1.instance.Content.Load<Texture2D>("Interface/Cursor");
            buttonTexture = Game1.instance.Content.Load<Texture2D>("Interface/Cursor");
        }
    }
}
namespace WindowsGame1.Classes.UI
{
公共静态类UILoader
{
公共静态纹理2D光标纹理;
公共静态纹理2D按钮纹理;
公共静空荷载()
{
cursorTexture=Game1.instance.Content.Load(“接口/光标”);
buttonTexture=Game1.instance.Content.Load(“接口/光标”);
}
}
}
我认为这可能与我使用另一个类来加载有关(我觉得很奇怪),所以我尝试将它全部移动到主类中的load content类,但是,它没有删除错误,而是在加载会话期间触发,现在在我尝试使用对象时触发(在对象应该被赋予一个值之后,因此不能为空)

我不认为问题出在我尝试使用的图片上,因为我已经将它添加到我正在使用的文件夹中(我会发布一张图片,但我没有足够的声誉)

如果有人知道这个错误的原因,我很乐意告诉你你的想法