无法在xna中加载图像

无法在xna中加载图像,xna,Xna,我是xna的begginer,我正在尝试加载图像,但它不工作,引发异常,未找到文件,我尝试了所有内容,到处冲浪,很多人问这个问题,找不到答案,请帮助,我遇到了很大的麻烦,这是代码 protected override void Initialize() { base.Initialize(); } /// <summary> protected override void LoadContent() {

我是xna的begginer,我正在尝试加载图像,但它不工作,引发异常,未找到文件,我尝试了所有内容,到处冲浪,很多人问这个问题,找不到答案,请帮助,我遇到了很大的麻烦,这是代码

    protected override void Initialize()
    {

        base.Initialize();
    }

    /// <summary>
    protected override void LoadContent()
    {
        // Create a new SpriteBatch, which can be used to draw textures.
        spriteBatch = new SpriteBatch(GraphicsDevice);
        mytexture = Content.Load<Texture2D>("gray");
        myrectangle = new Rectangle(100, 100, 40, 40);

        // TODO: use this.Content to load your game content here
    }

    /// <summary>
    /// UnloadContent will be called once per game and is the place to unload
    /// all content.
    /// </summary>
    protected override void UnloadContent()
    {
        // TODO: Unload any non ContentManager content here
    }

    /// <summary>
    /// Allows the game to run logic such as updating the world,
    /// checking for collisions, gathering input, and playing audio.
    /// </summary>
    /// <param name="gameTime">Provides a snapshot of timing values.</param>
    protected override void Update(GameTime gameTime)
    {
        // Allows the game to exit
        if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed)
            this.Exit();

        // TODO: Add your update logic here

        base.Update(gameTime);
    }

    /// <summary>
    /// This is called when the game should draw itself.
    /// </summary>
    /// <param name="gameTime">Provides a snapshot of timing values.</param>
    protected override void Draw(GameTime gameTime)
    {
        GraphicsDevice.Clear(Color.CornflowerBlue);

        // TODO: Add your drawing code here
        spriteBatch.Begin(SpriteSortMode.BackToFront, BlendState.AlphaBlend);
        spriteBatch.Draw(mytexture, myrectangle , Color.White);
        spriteBatch.End();

        base.Draw(gameTime);
    }

图像已添加到内容中

问题在于文件已被删除或移动,并且内容项目无法再找到该文件

查看内容项目下的图像列表。很可能在根中没有一个叫做灰色的。如果有,您可以检查以下几点:

如果它在文件夹中,您需要将其与您的 所容纳之物Load@FOLDERNAME/灰色的 确保它和Content.Load指令中的一样都是小写的 确保该文件存在。如果它列在那里,试着打开它。
谢谢大家,我找到了解决方案,这真是一个奇怪的解决方案,我只是做了一个新项目,复制了所有东西,我什么也没做,只做了一件事,但没做,总之非常感谢,你需要提供更多细节:它抛出了什么异常,它找不到什么文件?错误出现在哪个函数中?是否已将AssetName gray的图像添加到内容项目中?是否已设置contentloader的根文件夹?例外情况是未处理内容加载选项,并且未写入详细信息image not found,问题仅限于图像加载,是的,我添加了带有gray.png图像文件的图像,我正在尝试加载,它列在“内容”中,单击后会在“图形设计器类型”页面中打开,但不在文件夹中,并且与名称完全匹配