C# 在Monogame中加载内容时出现异常

C# 在Monogame中加载内容时出现异常,c#,xna,monogame,C#,Xna,Monogame,我无法加载纹理,我不知道为什么,因为我的代码非常简单 namespace Rogue_Like_LOL { public class Game1 : Game { GraphicsDeviceManager graphics; ScreenManager screenManager; public Game1() :base() { graphics = new G

我无法加载纹理,我不知道为什么,因为我的代码非常简单

namespace Rogue_Like_LOL
{
    public class Game1 : Game
    {
        GraphicsDeviceManager graphics;
        ScreenManager screenManager;

        public Game1()
            :base()
        {

            graphics = new GraphicsDeviceManager(this);
            graphics.PreferredBackBufferHeight = 720;
            graphics.PreferredBackBufferWidth = 1280;
            Content.RootDirectory = "Content";

            Art.Load(Content);
        }
    }
}
艺术中心:

    namespace Rogue_Like_LOL
    {
        static class Art
        {
            public static Texture2D Player { get; private set; }
            public static Texture2D PlayGame { get; private set; }
            public static Texture2D Exit { get; private set; }

            public static SpriteFont GameFont { get; private set; }

            public static void Load(ContentManager content)
            {
                // Player etc
                PlayGame = content.Load<Texture2D>("playgame");
                Exit = content.Load<Texture2D>("exit");

            }

    }
namespace Rogue\u Like\u LOL
{
静态课堂艺术
{
公共静态纹理2D播放器{get;private set;}
公共静态纹理2D游戏{get;private set;}
公共静态纹理2D出口{get;private set;}
公共静态SpriteFont GameFont{get;private set;}
公共静态无效加载(ContentManager内容)
{
//玩家等
PlayGame=content.Load(“PlayGame”);
退出=内容加载(“退出”);
}
}
以下是例外情况的详细信息:

System.ArgumentNullException未经处理HResult=-2147467261
Message=La valeur ne peut pasètre null。参数名称:图形 设备不能为空Source=MonoGame.Framework ParamName=Graphics 设备不能为空堆栈跟踪: §Microsoft.Xna.Framework.Graphics.Texture2D..ctor(GraphicsDevice graphicsDevice、Int32宽度、Int32高度、布尔mipmap、, SurfaceFormat格式,SurfaceType类型,布尔共享,Int32 排列) §Microsoft.Xna.Framework.Graphics.Texture2D..ctor(GraphicsDevice 图形设备,Int32宽度,Int32高度) ?.Microsoft.Xna.Framework.Graphics.Texture2D.PlatformFromStream(GraphicsDevice 图形设备(流) ?.Microsoft.Xna.Framework.Graphics.Texture2D.FromStream(GraphicsDevice 图形设备(流) §Microsoft.Xna.Framework.Content.ContentManager.ReadRawAsset[T](字符串) assetName,字符串原始名称(SetName) §Microsoft.Xna.Framework.Content.ContentManager.ReadAsset[T](字符串 资产名称,操作'1可记录可处置对象) §Microsoft.Xna.Framework.Content.ContentManager.Load[T](String assetName) 像Rogue\u LOL.Art.Load(ContentManager content)dans c:\Users\Monique Dumont\Programmation\Rogue Like LOL\Rogue Like LOL\Art Manager\Art.cs:ligne 22 类似流氓的游戏1..ctor()dans c:\Users\Monique Dumont\Programmation\Rogue-Like-LOL\Rogue-Like-LOL\Game1.cs:ligne 34 a Rogue_Like_LOL.Program.Main()dans c:\Users\Monique Dumont\Programmation\Rogue Like LOL\Rogue Like LOL\Program.cs:ligne 17 §System.AppDomain.\u nExecuteAssembly(运行时程序集,字符串[]args) §System.AppDomain.ExecuteAssembly(字符串汇编文件、证据汇编安全性、字符串[]参数) §Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly() §System.Threading.ThreadHelper.ThreadStart\u上下文(对象状态) §System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext、ContextCallback回调、对象状态、布尔值 (同步CTX) §System.Threading.ExecutionContext.Run(ExecutionContext ExecutionContext,ContextCallback回调,对象状态,布尔值 (同步CTX) §System.Threading.ExecutionContext.Run(ExecutionContext ExecutionContext,ContextCallback回调,对象状态) §System.Threading.ThreadHelper.ThreadStart()内部异常:


感谢您的关注。

我建议您在内容管理器准备好使用后加载内容。我不确定这是否能解决您的问题,但对我来说这似乎是一个可能的问题

为此:

protected override void LoadContent()
{
    Art.Load(Content);
}

你的纹理在“内容”中,对吗?不在任何子文件夹中?@DavorMlinaric是的,当然,我还检查了.png是否在“始终复制”上。内容应该在
LoadContent
中加载(更合适)或者通过重写其中一个来初始化游戏1的虚拟方法。请注意,重写初始化时,请确保调用
base.Initialize()
,因为这实际上是初始化基本游戏系统。