简体   繁体   English

NullReferenceException用于创建继承类的实例

[英]NullReferenceException on creating an instance of an inheriting class

I am writing my own game engine in XNA and started to port it into MonoGame so that I can put it on Android/iOS/Windows 8. For some reason I am getting a null reference exception when the main create a new game object. 我正在XNA中编写自己的游戏引擎,并开始将其移植到MonoGame中,以便我可以将它放在Android / iOS / Windows 8上。出于某种原因,当主要创建一个新游戏对象时,我得到一个空引用异常。 So the code that allocates the object is: 所以分配对象的代码是:

    static void Main(string[] args)
    {
        //game g = new game();
        using (game game = new game())
        {
            game.Run();
        }
    }

and the error is as 而错误是

    public lesaEngine()

which is the base constructor for the game object. 这是游戏对象的基础构造函数。

the inheritance is just as always 继承与往常一样

    class lesaEngine : Microsoft.Xna.Framework.Game
    class game : lesaEngine

Not sure whats going on here. 不知道这里发生了什么。 It works normally under normal XNA. 它在正常的XNA下正常工作。 I am using Visual Studio 2012 for the port. 我正在使用Visual Studio 2012作为端口。

Did you create a new Win8 monogame project? 你有没有创建一个新的Win8 monogame项目? if so the entry point should look more like this 如果是这样,入口点看起来应该更像这样

#if !NETFX_CORE 
  using (MyGame game = new MyGame()) 
  { 
      game.Run();
  } 
#endif 
#if NETFX_CORE 
  var factory = newMonoGame.Framework.GameFrameworkViewSource<MyGame>();
  Windows.ApplicationModel.Core.CoreApplication.Run(factory); 
#endif } 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM