我一直在嘗試使用我的C#XNA Game項目來獲取xWinForms 3.0庫(xna中具有表單支持的庫),但我一直在獲取同樣的問題。 我將引用添加到我的項目中,放入using語句中,聲明一個formCollection變量,然後嘗試初始化它。奇怪的「對象引用未設置爲對象的實例」涉及xWinForms
每當我跑我得到停止在這條線的項目:
formCollection = new FormCollection(this.Window, Services, ref graphics);
它給我的錯誤:
System.NullReferenceException was unhandled Message="Object reference not set to an instance of an object."
Source="Microsoft.Xna.Framework" StackTrace: at Microsoft.Xna.Framework.Graphics.VertexShader..ctor(GraphicsDevice graphicsDevice, Byte[] shaderCode) at Microsoft.Xna.Framework.Graphics.SpriteBatch.ConstructPlatformData() at Microsoft.Xna.Framework.Graphics.SpriteBatch..ctor(GraphicsDevice graphicsDevice) at xWinFormsLib.FormCollection..ctor(GameWindow window, IServiceProvider services, GraphicsDeviceManager& graphics) at GameSolution.Game2.LoadContent() in C:\Users\Owner\Documents\School\Year 3\Winter\Soen 390\TeamWTF_3\SourceCode\GameSolution\GameSolution\Game2.cs:line 45 at Microsoft.Xna.Framework.Game.Initialize() at GameSolution.Game2.Initialize() in C:\Users\Owner\Documents\School\Year 3\Winter\Soen 390\TeamWTF_3\SourceCode\GameSolution\GameSolution\Game2.cs:line 37 at Microsoft.Xna.Framework.Game.Run() at GameSolution.Program.Main(String[] args) in C:\Users\Owner\Documents\School\Year 3\Winter\Soen 390\TeamWTF_3\SourceCode\GameSolution\GameSolution\Program.cs:line 14 InnerException:
在一個項目中,我下載了用xWinForms,我把下面的代碼並編譯並運行沒有錯誤。 但是當我把它放在我的項目中時,我得到了錯誤。 我是否在包含dll或其他東西方面犯了一些愚蠢的錯誤?我一直在這個小時,我似乎無法找到任何會導致此問題的事情。
using xWinFormsLib;
public class Game2 : Microsoft.Xna.Framework.Game
{
GraphicsDeviceManager graphics;
SpriteBatch spriteBatch;
FormCollection formCollection;
public Game2()
{
graphics = new GraphicsDeviceManager(this);
Content.RootDirectory = "Content";
}
protected override void Initialize()
{
// TODO: Add your initialization logic here
base.Initialize();
}
protected override void LoadContent()
{
// Create a new SpriteBatch, which can be used to draw textures.
spriteBatch = new SpriteBatch(GraphicsDevice);
formCollection = new FormCollection(this.Window, Services, ref graphics);
}
protected override void Update(GameTime gameTime)
{
base.Update(gameTime);
}
protected override void Draw(GameTime gameTime)
{
base.Draw(gameTime);
}
}
任何幫助將不勝感激._。